How to send the authorization header using Axios

I was doing some work with the WordPress API, and I had to authenticate to perform a POST request to a website.

The easiest way for me was to use basic authentication.

I was using Axios, so I set the Authorization header to the POST request in this way:

const username = ''
const password = ''

const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')

const url = 'https://...'

axios.post(url, {
  headers: {
    'Authorization': `Basic ${token}`
  }
})

#javascript #nodejs #axios #webdev

How to send the authorization header using Axios
88.30 GEEK