Axios put request example
Example 1: how to post in axios
axios({
method: 'post',
url: '/login',
data: {
firstName: 'Finn',
lastName: 'Williams'
}
});
Example 2: axios api post request
import qs from 'qs';
const data = { 'bar': 123 };
const options = {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: qs.stringify(data),
url,
};
axios(options);
Example 3: axios instance
const getUser = axios.create({
baseURL: 'https://randomuser.me/api/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});
getUser().then(response => console.log(response))
Example 4: how to use axios get
const req = async () => {
const response = await axios.get('https://dog.ceo/api/breeds/list/all')
console.log(response)
}
req()
Example 5: axios put
const res = await axios.put('https://httpbin.org/put', { hello: 'world' });
res.data.headers['Content-Type'];
Example 6: how to make request with axios
const axios = require('axios');
async function makeGetRequest() {
let res = await axios.get('http://webcode.me');
let data = res.data;
console.log(data);
}
makeGetRequest();