Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cordova-plugin-advanced-http vs @angular/common/http

I want to create an API helper class to serve for all types of rest api calls in the app. I have been using the angular httpClient class

import {HttpClient} from '@angular/common/http'

to do API interaction but recently came across https://ionicframework.com/docs/native/http/

Can anybody describe the difference between the two so that I could decide which one would be better as per my requirement.

like image 357
Apogee Avatar asked Jan 02 '19 08:01

Apogee


1 Answers

For starters, Angulars Http Module is based on Observables which are widely used within Angular and thus Ionic themselves. The Ionic Http Module instead is based on Promises, which itself is totally fine if you want to use them.

Since this is an Ionic Native Module this also means that the app is not going to make these requests using either the underlying Java (Android) or Objective-C (iOS) function instead of a Javascript function (Please anybody correct me if I am wrong here)

However the main advantages are listed on the Github Repo of the Ionic Http Module:

  • Background threading - all requests are done in a background thread.
  • Handling of HTTP code 401 - read more at Issue CB-2415.
  • SSL Pinning - read more at LumberBlog.

The first point seems to be the most appealing, since it is a feature which is not merely solving a problem but adding functionality. I cannot tell exactly how big of an advantage it is to run these in a background thread but I also doubt that this will have a big impact unless your app is very network-expensive.

So Ionics native module solves exactly these problems which apparently come with using plain Javascript functions for making http requests from a containered mobile app.

I would say that the Ionic Native solution should only be used in case you encounter any of the above problems. If not, you would simply add a new dependency which uses another paradigm (promises) than probably any tutorial on Angular which you can find. You simply reduce complexity and bundle size by not using it if it isn't needed.

Angular comes bundled with the Http Module and it is well maintained, also you will find much more help online for this package.

like image 169
mchl18 Avatar answered Nov 11 '22 21:11

mchl18