vdenotaris
vdenotaris

Reputation: 13637

Request parameters while consuming a REST API in node.js

I would like to consume a REST service in Node.js using request.js, as follows:

var request = require('request');
request.get({
  url: 'https://www.googleapis.com/storage/v1/b',
  auth: {
    'bearer': 'oauth2_token'
  }
}, function(err, res) {
  console.log(res.body);
});

However, I would like to specify also a set of request parameters, such as project, prefix, etc. (as specified at https://cloud.google.com/storage/docs/json_api/v1/buckets/list).

How can I pass these parameters in the request for consuming the API service?

Upvotes: 2

Views: 463

Answers (1)

Paul Fitzgerald
Paul Fitzgerald

Reputation: 12129

You can pass in qs as the additional queries. See example below:

 const queryObject = { project: 'project', prefix: 'prefix' };

 request.get({
    url: 'https://www.googleapis.com/storage/v1/b',
    qs: queryObject,
    auth: {
      'bearer': "oauth2_token"
    }
  }, function(err, res) {
    console.log(res.body);
  });

See here for github issue.

Upvotes: 1

Related Questions