needle icon indicating copy to clipboard operation
needle copied to clipboard

GET requests with Promise interface do not send query parameters

Open aoberoi opened this issue 7 years ago • 4 comments

I'm trying to use the Promise based interface to make a GET request that includes query string parameters. I've created a URL using https://postb.in to observe the request as its received.

needle('get', 'http://postb.in/xjXUccQg', { token: 'hello' })
  .then(console.log)
  .catch(console.error);

The above code never sends the token parameter. When using the callback interface, I am able to get this to work.

needle.request('get', 'http://postb.in/xjXUccQg', { token: 'hello' }, (error, response) => {
  if (error) { return console.error(error); }
  console.log(response);
});

aoberoi avatar Sep 19 '18 22:09 aoberoi

You're right. The Promise-based interface currently does not expect any params for GET requests. This should probably change, though, to reflect the same behaviour as in needle.request. Thanks for the heads up!

tomas avatar Sep 20 '18 14:09 tomas

Any workaround ?

I am trying below code that always throwing error.

needle('get','https://url.com/v1/get/match',params,options, function(err, resp ) {

Sreekusak avatar Feb 08 '19 08:02 Sreekusak

@Sreekusak if you look at the code https://github.com/tomas/needle/blob/master/lib/needle.js#L347 you can do the same thing. querystring can be imported like import * as querystring from 'needle/lib/querystring'; Would be nice to have it still but that should work for you.

triwav avatar Mar 19 '20 19:03 triwav

Happy to accept pull requests if anybody's up to the challenge. :)

tomas avatar Mar 19 '20 20:03 tomas