Simplifying angular 2’s http

Barna Toth
Frontend journeys
Published in
1 min readNov 27, 2016

Angular 2’s http was designed to encourage the usage of Observables which is great.

The only problem is that for a simple XMLHTTP request it’s a bit too much code:

Okay I know with Observables I can cancel my request and I get all the mightiness of its operators but there’s one problem.

I don’t need all of this.

I only need to create a request and that’s it. None the less I’d like to use async/await which — for me — would be super convenient.

And I don’t want to handle every error individually I’d like to write a custom response interceptor that will handle all my errors and simply throw an error at the call location.

So I’ve created a library called “angular2-cool-http” to solve all these issues.

With this library you can leverage several cool features:

  • global http settings (base url, withCredentials)
  • request interceptors
  • response interceptors
  • automatic cookie to header sending

And of course super easy usage:

Yey! Just what I needed — hope you’ll love it too.

Thanks for reading.

--

--