11.0.1 • Published 1 year ago

ionic-native-http-connection-backend v11.0.1

Weekly downloads
1,091
License
MIT
Repository
github
Last release
1 year ago

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

11.0.0

2 years ago

11.0.1

1 year ago

10.0.0

2 years ago

9.0.2

2 years ago

9.0.1

3 years ago

9.0.0

3 years ago

8.1.4

3 years ago

8.1.3

3 years ago

8.1.2

3 years ago

6.2.5

3 years ago

8.1.1

4 years ago

6.2.4

4 years ago

8.1.0

4 years ago

8.0.0

4 years ago

6.2.3

4 years ago

7.0.3

4 years ago

7.0.2

4 years ago

7.0.1

4 years ago

6.2.2

4 years ago

4.0.12

4 years ago

6.2.1

5 years ago

4.0.11

5 years ago

6.2.0

5 years ago

6.1.1

5 years ago

6.1.0

5 years ago

6.0.0

5 years ago

4.0.10

5 years ago

4.1.0

5 years ago

5.0.4

5 years ago

5.0.3

5 years ago

4.0.9

5 years ago

4.0.8

5 years ago

5.0.2

5 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.0.7

6 years ago

4.0.6

6 years ago

4.0.5

6 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago