Reputation: 87
I call another api in NodeJS express api with request payload using certificate with Post request type but the payload is not accepting. The problem is, how to feed the payload data with Post request inside the Node api?
Upvotes: 0
Views: 882
Reputation: 190
Here is an example with Axios
const axios = require('axios');
var dataToPost = {
email: "your email",
password: "your password"
};
let axiosConfiguration = {
headers: {
'Content-Type': 'application/json;charset=UTF-8',
"Access-Control-Allow-Origin": "*",
}
};
axios.post('endpoint or url', dataToPost, axiosConfiguration)
.then((res) => {
console.log("Response: ", res);
})
.catch((err) => {
console.log("error: ", err);
})
Upvotes: 1
Reputation: 295
Just pass the payload with comma separated URL, Example : await axios.post('http://localhost:4000/createUser', data );
where data will be payload for another API
Upvotes: 1