Matanya Cohen
Matanya Cohen

Reputation: 334

Angular HttpClient constructor and abstract HttpHandler class

I try understand why HttpClient constructor not have true implementation.

Actually the constructor include parameter typed as abstract class (HttpHandler). So why HttpHandler not have implementation? Or why his implementetion so secret to buried it deep in DI system?

And where I can find his implementation code?

Upvotes: 0

Views: 589

Answers (1)

Amir Arbabian
Amir Arbabian

Reputation: 3699

Hm, I've found something on angular repo. Here you can see that HttpBackend implements HttpHandler, but it's abstract too. But further you can find different implementations of HttpBackend like HttpXhrBackend or JsonpClientBackend. HttpXhrBackend it's implementation that uses XMLHttpRequest API to send requests to a backend server. JsonpClientBackend - performs JSONP style requests (without using XMLHttpRequest object at all).


Overall HttpHandler it's an abstraction of service that handles HttpRequest and returns HttpResponse in Observable manner, so it creates this Observable inside from HttpEvents that browser API provides. For example XMLHttpRequest has events like onLoad, onError, onUpProgress and HttpXhrBackend which is implementation of HttpHandler transforms all these events to Observable stream. Hope that makes sense.

Upvotes: 1

Related Questions