0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I still not understand why not follow after OOP principle, And put all into the constructor. Something like call to XMLHttpRequest wrapper. Also I yet not sure understand what happened under hood when I Inject the HttlClient first time on my component constructor. I gues have some code register to DI system, that say: "If injectable is HtpClient please run the follow code"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.