In the docs for HttpClient
, there's a mention of HttpObserve
. However, when I Google for it, it seems (based on different blogs and forums) that it's been removed. It's definitely not present in Angular 9 (under @angular/common/http
, at least). Various sources provide different suggestions and I sense that there's more assuming than knowing in those.
According to e.g. this declaration there's something of type HttpObserve
supposed to be provided (or skipped, of course, which most people probably do). I've prepared the following sample.
const headers: HttpHeaders = new HttpHeaders();
const observe: HttpObserve = null;
const params: HttpParams = new HttpParams();
const reportProgress = false;
const responseType = "json";
const withCredentials = true;
VS Code marks the second line as incorrect as the type isn't recognized. I couldn't find a reliable, credible source of info on how to handle it, so I get cautious. There's also seemingly different responses depending on the version since 5th through 8th and not that many on the current 9th. Having time to research it in depth, I'm asking here.
What, if anything, should/could be provided as type for the observe
parameter?
You can see its definition in the source code (you can find it via GitHub search):
export type HttpObserve = 'body'|'events'|'response';
or listed out in the various overloads in the HttpClient
API docs you linked to. It is present in Angular 9 (see e.g. 9.1.x tag), it's just not exposed as part of the module definition.
Again, this is a string literal type; the value must be one of those three string literals. For example, in the HTTP guide they show it being set to 'response'
to read the whole response (rather than the default 'body'
):
getConfigResponse(): Observable<HttpResponse<Config>> {
return this.http.get<Config>(
this.configUrl, { observe: 'response' });
}
In terms of use in your code, you have all of the same options I outlined before to define that value and your options object.