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, 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'', { hello: 'world' }, {
  headers: {
    // 'application/json' is the modern content-type for JSON, but some
    // older servers may use 'text/json'.
    // See:
    'content-type': 'text/json'
});['Content-Type']; // text/json

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

More Axios Tutorials