axios js send body with post request code example
Example 1: axios post with header
// Send a POST request
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
},
headers: {'Authorization': 'Bearer ...'}
});
Example 2: axios post with body
const body = { a: 10 };
axios.post('/save', body);
// Axios automatically serializes JavaScript objects to JSON
// when passed to the axios.post function as the second parameter.
// This eliminates the need to serialize POST bodies to JSON.