2

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.