No way to set global options on HttpClient ( { observe: 'response' } )
See original GitHub issueπ bug report
Affected Package
The issue is caused by package @angular/....HttpClient / HttpInterceptor
Is this a regression?
Yes, the previous version in which this bug was not present was: ....Description
A clear and concise description of the problem...There doesnβt seem to be a way to set global options for an HttpClient. The only close option I see is configuring an HttpInterceptor and set the options within each request.
const req = _request.clone(<Update Object>);
It doesnβt look like the update object is aware of the HttpClient options such as { observe: 'response }
clone(update: {
headers?: HttpHeaders;
reportProgress?: boolean;
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
body?: T | null;
method?: string;
url?: string;
setHeaders?: {
[name: string]: string | string[];
};
setParams?: {
[param: string]: string;
};
}): HttpRequest<T>;
π¬ Minimal Reproduction
https://stackblitz.com/...π₯ Exception or Error
π Your Environment
Angular Version:
Anything else relevant?
Iβm not clear if there is some other way to handle this as my use case is to simply get the Http Response Code from the response. Of course, I can configure the { observe: βresponseβ } on every call, but that is error prone (someone would eventually not add it).
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to set the { observe: 'response' } option globally in ...
So, is there, if any, method to set the { observe: 'response' } option globally, e.g. via the HttpInterceptor ? clone(update: { headers?:...
Read more >Communicating with backend services using HTTP - Angular
The observe option specifies how much of the response to return ... for example, the service set the default headers using the headers...
Read more >The new Angular HttpClient API - Medium
The HttpClient API was introduced in the version 4.3.0. It is an evolution of the existing HTTP API and has it's own package...
Read more >Angular HttpClient post - ConcretePage.com
The HttpClient.post method can use observe property in http options to define whether we want complete response or body only or events only....
Read more >Angular Basics: How To Use HttpClient in Angular - Telerik
options β It is used to configure the HTTP request. It is optional and of type object , and its default value is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
One reason I could think of for not being able to set the response format globally is that it would break libraries that also use
HttpClient
themselves. Furthermore, API consumers would not be able to be type-checked properly, this is also why an interceptor canβt change the response format right now.This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.