18

I am trying to make a request to an API using the get method in the https module.

Looking at HTTPS request in NodeJS, I've got a long way, but my request doesn't appear to include the query parameters…

Using the example from above, with my mods:

var $q = require('q'),
    _ = require('lodash'),
    path = require('path'),
    Qs = require('qs'),
    path = require('path'),
    uuid = require('node-uuid'),
    https = require('https');

var params = {
  schema: '1.0',
  form: 'json',
  username: 'name'
}
var options = {
  host: 'openshift.redhat.com',
  port: 443,
  path: '/broker/rest/api',
  query: params
};

var req = https.get(options, function(res) {

1 Answer 1

30

According to https://nodejs.org/api/https.html#https_https_request_options_callback there is no option called "query". You need to include the query parameters to the "path".

Request path. Defaults to '/'. Should include query string if any. E.G. '/index.html?page=12'.

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

4 Comments

That's great! Don't know where I got that query option… Apparently I can't accept your answer yet, but I will! Thank you
You could also use github.com/ljharb/qs to easily serialize an object to a query string and not have to do that string hacking manually.
We are actually using qs, so from the example above, I have: + path: '/broker/rest/api' + Qs.stringify(params).
I can't find the quoted text in the documentation any longer, but it still seems to be correct.

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.