Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einnar82/82d9b0e601d6748ec2435ff21a20527e to your computer and use it in GitHub Desktop.
Save einnar82/82d9b0e601d6748ec2435ff21a20527e to your computer and use it in GitHub Desktop.
const axios = require('axios').default;
axios.interceptors.request.use(x => {
const headers = {
...x.headers.common,
...x.headers[x.method],
...x.headers
};
['common','get', 'post', 'head', 'put', 'patch', 'delete'].forEach(header => {
delete headers[header]
})
const printable = `${new Date()} | Request: ${x.method.toUpperCase()} | ${x.url} | ${ JSON.stringify( x.data) } | ${ JSON.stringify(headers)}`
console.log(printable)
return x;
})
axios.interceptors.response.use(x => {
const printable = `${new Date()} | Response: ${x.status} | ${ JSON.stringify(x.data) }`
console.log(printable)
return x;
})
axios.post('https://jsonplaceholder.typicode.com/posts', {
myProperty: true
}).then()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment