ionic-native-http-connection-backend
TypeScript icon, indicating that this package has built-in type declarations

11.0.1 • Public • Published

ionic-native-http-connection-backend

version MIT License

This library adds @awesome-cordova-plugins/http (when available) as a connection backend to Angular's Http and HttpClient

Motivation

Now that Apple promotes/requires the use of WKWebView instead of the deprecated UIWebView, Ionic has switched newly created apps over via their cordova-plugin-ionic-webview (and Cordova offers it via their cordova-plugin-wkwebview-engine). That causes requests that used to work just fine to fail with CORS errors.

The real solution of course is to fix the CORS issues server side - but this may not be possible with e.g. 3rd party APIs.

Even though there is a way to solve CORS issues without changing server's response header by using @awesome-cordova-plugins/http, this only works on device and doesn't provide all the power of Angular's Http and HttpClient.

How it works

  • The library provides a HttpBackend interface for Angular's HttpClient
  • This HttpBackend interface tries to use @awesome-cordova-plugins/http whenever it is possible (= on device with installed plugin)
  • If HttpBackend finds it impossible to use @awesome-cordova-plugins/http, it falls back to standard Angular code (HttpXhrBackend, which uses XmlHttpRequest)

This strategy allows developers to use Angular's HttpClient transparently in both environments: Browser and Device.

Installation

npm install --save ionic-native-http-connection-backend

Then follow instructions at https://ionicframework.com/docs/native/http/#installation

Usage

Add NativeHttpModule, NativeHttpBackend and NativeHttpFallback into the application's module

import { NgModule } from '@angular/core';
import { HttpBackend, HttpXhrBackend } from '@angular/common/http';
import { NativeHttpModule, NativeHttpBackend, NativeHttpFallback } from 'ionic-native-http-connection-backend';
import { Platform } from '@ionic/angular';

@NgModule({
    declarations: [],
    imports: [
        NativeHttpModule
    ],
    bootstrap: [],
    entryComponents: [],
    providers: [
        {provide: HttpBackend, useClass: NativeHttpFallback, deps: [Platform, NativeHttpBackend, HttpXhrBackend]},
    ],
})
export class AppModule {
}

Contributing

Contributing guidelines could be found in CONTRIBUTING.md

Troubleshooting

TROUBLESHOOTING.md

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
11.0.1387latest
6.2.516angular8-ionic4-native5
4.1.014ionic3-native5
4.0.121ionic3-native4

Version History

VersionDownloads (Last 7 Days)Published
11.0.1387
11.0.01
10.0.023
9.0.220
9.0.11
9.0.00
8.1.416
8.1.30
6.2.516
8.1.21
8.1.10
6.2.45
8.1.01
8.0.01
6.2.33
7.0.31
7.0.22
7.0.11
6.2.22
4.0.121
6.2.13
4.0.111
6.2.01
6.1.13
6.1.01
6.0.00
4.0.1012
4.1.014
5.0.46
5.0.31
4.0.93
4.0.81
5.0.22
5.0.11
5.0.01
4.0.77
4.0.61
4.0.51
4.0.42
4.0.31
4.0.21
4.0.11
4.0.01
3.0.01
2.1.01
2.0.11
2.0.01
1.2.51
1.2.41
1.2.31
1.2.21
1.2.11
1.2.01
1.1.10
1.1.01
1.0.01

Package Sidebar

Install

npm i ionic-native-http-connection-backend

Weekly Downloads

559

Version

11.0.1

License

MIT

Unpacked Size

40.8 kB

Total Files

56

Last publish

Collaborators

  • sneasio