Being a JS developer, No matter what JS library/Framework you work with, There is always a need to understand how things work under the hood.
I recently started working with Angular, And of course, I had to use it’s HTTP service for my project, And there is one thing that caught my eyes that HTTP call returns an (RxJs)Observable (I was expecting Promise :)), Which makes life a lot easier.
Which raises a question, how angular does that, Or how can I do that without using Angular’s HttpClient, So I decided to write my own service to do that.
I chose to write this service for Fetch API (Although Angular’s HTTPClient rests on the XMLHttpRequest interface exposed by browsers) as It provides an API for both client-side applications and server-side which in returns facilitates Server-side rendering.
Enough theory, Let’s code now
Now you can call this method to serve the purpose as follows