axiosでGET,POST
For Node.js
const axios = require('axios');
GET
const config = { 'Accept': 'application/json' };
axios.get('https://httpbin.org/get', config)
.then((response) => {
console.log(response);
// Do something with response
})
.catch((error) => {
console.log(error);
// Do something with error
})
POST
const data = { user: 'john', pass: 'shiba' };
// if you want to set headers
const headers = { 'Content-Type': 'application/json' };
axios.post('https://httpbin.org/post', data, { headers: headers })
.then((response) => {
console.log(response);
// Do something with response
})
.catch((error) => {
console.log(error);
// Do something with error
})
appendix
https://httpbin.org って便利〜