Bunny
Bunny

Reputation: 87

How to feed the payload data with Post request inside the Node api?

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?

Express Setting

Request Options with Payload and Certificate

Upvotes: 0

Views: 882

Answers (2)

Nabeel Sajid
Nabeel Sajid

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

Saket Agarwal
Saket Agarwal

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

Related Questions