ang
ang

Reputation: 1581

How to Set Params with Node Get Request

I am trying to make a get request using the NPM Request module and am having trouble passing in a params argument.

Going through the docs I can't tell what the correct syntax is.

makeRequest(req, res, num, cookie) {
  request({
    headers: {
      'Cookie': cookie
    },
    url: 'https://api.domain.com/path',
    params: num // this is incorrect
  },
  (error, response, body) => {
      res.json({
        msg: "Success"
      })
    }
  })
}

How can I pass a params argument into a request?

Upvotes: 0

Views: 762

Answers (1)

Mikell-S
Mikell-S

Reputation: 42

https://www.npmjs.com/package/request

qs - object containing querystring values to be appended to the uri

request({
    headers: {
      'Cookie': cookie
    },
    url: 'https://api.domain.com/path',
    qs: { num: 1} 
 })

This should create a url

https://api.domain.com/path?num=1

Upvotes: 1

Related Questions