How to Send Headers With an Axios POST Request

Jul 28, 2021

To send an Axios POST request with headers, you need to use the headers option. With axios.post(), the first parameter is the URL, the 2nd parameter is the request body, and the 3rd parameter is the options. For example, below is how you set the Content-Type header on an HTTP POST request.

const res = await axios.post('https://httpbin.org/post', { hello: 'world' }, {
  headers: {
    // 'application/json' is the modern content-type for JSON, but some
    // older servers may use 'text/json'.
    // See: http://bit.ly/text-json
    'content-type': 'text/json'
  }
});

res.data.headers['Content-Type']; // text/json

Did you find this tutorial useful? Say thanks by starring our repo on GitHub!

More Axios Tutorials