question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow to setFullResponse per request

See original GitHub issue

I generally like extracting the data field of my API responses. However, sometimes (only) I need to access headers of a particular request. Currently, I’m doing it like:

Restangular.setFullResponse(true).all('user').getList()
.then(function(response){
  Restangular.setFullResponse(false);
  totalUsers = response.headers('X-Total-Count');
  currentPageUsers = response.data;
});

But if there are other simultaneous Restangular requests, they may fail as they expect no full response. Ability to set the full response per request would solve the problem.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
chandrewzcommented, Feb 22, 2019

In case someone stumbles on this thread, you can do something like this now for a single request using setFullResponse:

Restangular.withConfig((RestangularConfigurer) => {
    RestangularConfigurer.setFullResponse(true);
}).all(url);
0reactions
tvStaticcommented, Jun 26, 2018

@poppahorse a follow up to this. The above code results in the same problem as the OPs - the global setFullResponse is set as each request goes out, so the value may not be correct depending on the timing of the responses.

The solution, as far as I can see is use addResponseInterceptor instead, as the response is parsed straight afterwards. For the original case:

RestangularProvider.addResponseInterceptor(
    function (data, operation, what) {
        if (operation === "getList" && what === "user") {
            RestangularProvider.setFullResponse(true);
        } else {
            RestangularProvider.setFullResponse(false);
        }
   
        return data;
    }
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Access-Control-Allow-Methods - HTTP - MDN Web Docs
The Access-Control-Allow-Methods response header specifies one or more methods allowed when accessing a resource in response to a preflight  ...
Read more >
How can I capture all network requests and full response data ...
You can enable a request interception with page.setRequestInterception() for each request, and then, inside page.on('request') , you can use ...
Read more >
Advanced Usage — Requests 2.28.1 documentation
Whenever you receive a Response object from an API call or a Session call, the request attribute is actually the PreparedRequest that was...
Read more >
HTTP/1.1: Method Definitions
This allows user agents to represent other methods, such as POST, PUT and DELETE, ... The response to a GET request is cacheable...
Read more >
HTTP Request Response Headers Tutorial In Detail - YouTube
In this tutorial you will learn about HTTP Request and response headers from basics in detail. I have exlain http request and http...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found