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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With