So far I understand that _http.get() returns an observable and will
also provide http-response object (as next or callback function
The signature for the
request method (which is what is called by
get internally) is :
which means that it returns an observable that emits items of type
any. One of the values it returns is
HttpResponse. However, depending on the
observe parameter it can return text as in
response.body or parsed JSON as in
is .map() function acting just on the response object and will not
change the return type of the whole _http.get() function. (return type
remains the same as observable)? Is my assumption correct?
map operates on the values emitted by the observable. And the function signature doesn't explicitly specify these types and instead uses a generic type
Can we add .map() to all async functions
map is specific to the RxJs library. It's not
map from the Array.prototype.map.
In general, if the above is true, how does JS figure out what kind of
chaining function would work on the callback data and which would work
on the return type?
You need to read about RxJs operators and lettable operators here. RxJs will execute each operator one after the other. All operators work on the data emitted by an observable, in the case of HttpClient it's either
You can read more about how observable chain works in
HttpClient in the article:
- Insider’s guide into interceptors and HttpClient mechanics in Angular