Access to headers in request-promise get response

request-promise-native
request-promise typescript
request-promise-native post example
nodejs request headers
request-promise graphql
javascript request get
request-promise file upload
request-promise async await

I am complete newbie to JS world. I am trying to write a test case that tests user's actions on a site. I am using request-promise module to test the asyn calls. I could not find any api documentation for request-promise. How do I get access to status code of the response? Right now it prints undefined. Also, can anyone please confirm, how do we know what promise returns when it is successful, is it a single value that it resolves to or all the parameters that the async function returns. How do we know what are the parameters to function() in request.get(base_url).then(function(response, body).

var request = require("request-promise");
var promise = require("bluebird");
//
var base_url = "https://mysignin.com/"
//
describe("My first test", function() {
 it("User is on the sign in page", function(done) {
    request.get(base_url).then(function(response, body){
     // expect(response.statusCode).toBe('GET /200');
      console.log("respnse " + response.statusCode);
      console.log("Body " + body);
      done();
    }).catch(function(error) {
        done("Oops somthing went wrong!!");
    });
 });
});

By default, the request-promise library returns only the response itself. You can, however, pass a simple transform function in your options, which takes three parameters and allows you to return additional stuff.

So if I wanted the headers plus the response returned to me, I would just do this:

var request = require('request-promise');
var uri = 'http://domain.name/';

var _include_headers = function(body, response, resolveWithFullResponse) {
  return {'headers': response.headers, 'data': body};
};

var options = {
  method: 'GET',
  uri: uri,
  json: true,
  transform: _include_headers,
}

return request(options)
.then(function(response) {
  console.log(response.headers);
  console.log(response.data);
});

Hope that helps.

No response headers in response object · Issue #74 · request , Maybe get the latest version of Request-Promise and Request? https://​developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-  Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

By default request-promise returns just the response body from a request. To get the full response object, you can set resolveWithFulLResponse: true in the options object when making the request. Example in the docs

var request = require('request-promise');

request.get('someUrl').then(function(body) {
  // body is html or json or whatever the server responds
});

request({
  uri: 'someUrl',
  method: 'GET',
  resolveWithFullResponse: true
}).then(function(response) {
  // now you got the full response with codes etc...
});

how could I get response header · Issue #17 · request/request , It seems the return value is response body, how could I get response /request/​request-promise#get-the-full-response-instead-of-just-the-body  Access to headers in request-promise get response (3) By default, the request-promise library returns only the response itself. You can, however, pass a simple transform function in your options, which takes three parameters and allows you to return additional stuff.

Just passing resolveWithFullResponse: true with in the get options should fetch the response headers.

request-promise, The simplified HTTP request client 'request' with Promise support. Powered by Bluebird. Gets the contents of a header that was returned with the response. HttpWebResponse.GetResponseHeader(String) Method (System.Net) | Microsoft Docs Skip to main content

Tsalikidis answer is correct. As for:

Also, can anyone please confirm, how do we know what promise returns when it is successful, is it a single value that it resolves to or all the parameters that the async function returns

A promise (Promise/A+ compliant) always return one single value. Of course this value can be a deeply nested object with tons of information in it. But .then(function(response,body){ is inherently wrong.

A library that sends back a promise should document the format of the returned object.

request/request-promise, Hello I am trying to figure out a way to use node-replay with request-promise out-of-the-box it seems like the how can i access the response headers? Hello, how do I pass query parameters into the rp(options) for a GET method? How to access http response headers [duplicate] Ask Question Asked 6 years, 9 months ago. How does Access-Control-Allow-Origin header work? 5223.

How to fetch JSON using an object with request-promises , Request-promise uses bluebird which provides much more like the finally method. If you don't use these catch() will return a native promise instead of a Bluebird promise. Ba Ba K. @cyclops24 how can i access the response headers? Request-Promise adds a Bluebird-powered .then() method to Request call objects. By default, http response codes other than 2xx will cause the promise to be rejected. This can be overwritten by setting options.simple = false. Also check out the new libraries that are very similar to request-promise v4:

request-promise JavaScript and Node.js code examples, I get the data back from the server and could PARSE is fine. I added webhook.​jovo.cloud in my MySql access list already to make How will I tell request-​promise-native that this is a post request? /Promise) API - Intercept request and response - Transform request and response data - Cancel requests One way to solve that issue is to specify from your backend which one of the pairs {key: value} of your headers you want to expose. Using a java backend, you can add the following lines:

squarecapadmin/request-promise · Gemfury, getCategories(token) { return request .get({ url: `${api}/api/smrt/categories`, json: true, headers: { Authorization: `Bearer ${token}` } }) .catch(errorHandler); }. using "access-control-expose-headers". because not all headers are allowed to be accessed from the client side, you need to expose them from the server side also in your frontend, you can use new HTTP module to get a full response using { observe: 'response'} like.

Comments