axios with json file code example
Example 1: axios response.json
const axios = require('axios');
const res = await axios.get('https://httpbin.org/get', { params: { answer: 42 } });
res.constructor.name;
res.data;
res.data instanceof Object;
Example 2: sending api request in axios with files
let headers = {
Authorization: "token",
'Content-Type':'multipart/form-data'
};
let formData = new FormData();
for(let key in files){
formData.append('files[][file]', files[key].file, files[key].file.name)
formData.append('files[][file_type_id]', files[key].fileType)
}
axios
.post(
"/api/files",
formData,
{ headers }
)
.then(()=>{console.log('It Works')})