Answers for "how to pass multiple headers in axios"

15

pass header in axios

const headers = {
  'Content-Type': 'application/json',
  'Authorization': 'JWT fefege...'
}

axios.post(Helper.getUserAPI(), data, {
    headers: headers
  })
  .then((response) => {
    dispatch({
      type: FOUND_USER,
      data: response.data[0]
    })
  })
  .catch((error) => {
    dispatch({
      type: ERROR_FINDING_USER
    })
  })
Posted by: Guest on August-17-2020
1

axios multiple request

// set requests
const reqOne = axios.get(endpoint);
const reqTwo = axios.get(endpoint);

axios.all([reqOne, reqTwo]).then(axios.spread((...responses) => {
  const responseOne = responses[0]
  const responseTwo = responses[1]
})).catch(errors => {
  // react on errors.
})
Posted by: Guest on October-26-2020

Code answers related to "how to pass multiple headers in axios"

Browse Popular Code Answers by Language