1

I want to send some post data to an api

10.11.12.13/new/request/create

this is an API to create a new request in portal. now I am making one application in NodeJs and want to create request from node js application. now I have to send in this format

{"user":"demo", "last_name":"test","contact":"989898989"}

so how can I send data on above url to create a new request.

I am a beginner in NodeJs and don't have much idea. any help will be appreciated.

Thanks in advance

3

3 Answers 3

1

I would recommend to use axios or any other request lib :

const axios = require('axios');

axios.post('10.11.12.13/new/request/create', {
  user: 'demo',
  last_name: 'test',
  contact: '989898989',
});
Sign up to request clarification or add additional context in comments.

Comments

1

here is an example using request module

    var headers = {
    'Content-Type': 'application/json'
}
var options = {
    url: "10.11.12.13/new/request/create" ,
    method: 'POST',
    headers: headers,
    json: true,
    body: {user:"demo", last_name:"test",contact:"989898989"}
}
request(options, function (error, response, body) {
    if (error) {
        //do something
    }
    console.log(body)//do something with response
})

Comments

0

You can use postman REST client for GET method using your URL and Body (which you want to post) and click on * Code * and select NodeJS and their you will find code generated for you to work with. Here is the link https://www.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets

With my experience, it is good to start with Request package for node js. Here is the link for your reference: https://www.npmjs.com/package/request

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.