I wrote the axios POST request as recommended in the npm package documentation:
var data = {
'key1': 'val1',
'key2': 'val2'
}
axios.post(Helper.getUserAPI(), data)
.then((response) => {
dispatch({type: FOUND_USER, data: response.data[0]})
})
.catch((error) => {
dispatch({type: ERROR_FINDING_USER})
})
And it works, but now I have changed my internal API to accept headers.
Content-Type: 'application / json'
Authorization: 'JWT fefege ...'
Now this request works fine on Postman, but when I write the axios call, I follow this link and cannot make it work.
I keep getting an error 400 BAD Request.
Here is my modified request:
axios.post(Helper.getUserAPI(), {
headers: {
'Content-Type': 'application/json',
'Authorization': 'JWT fefege...'
},
data
})
.then((response) => {
dispatch({type: FOUND_USER, data: response.data[0]})
})
.catch((error) => {
dispatch({type: ERROR_FINDING_USER})
})
Any help is greatly appreciated.
source
share