# ionic-native-http-connection-backend

> A solution to CORS problem with Ionic and WKWebView

Latest version **11.0.1** (published 2022-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install ionic-native-http-connection-backend
pnpm add ionic-native-http-connection-backend
yarn add ionic-native-http-connection-backend
bun add ionic-native-http-connection-backend
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 11.0.1 |
| Published | 2022-11-20 |
| First published | 2017-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 39.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 160 |
| Author | Dmytro Snisarenko |
| Maintainers | sneasio |
| Keywords | ionic, ionic3, wk-web-view, cors |

## Links

- npm: https://www.npmjs.com/package/ionic-native-http-connection-backend
- Repository: https://github.com/sneas/ionic-native-http-connection-backend
- Homepage: https://github.com/sneas/ionic-native-http-connection-backend#readme
- Issues: https://github.com/sneas/ionic-native-http-connection-backend/issues
- npm.io page: https://npm.io/package/ionic-native-http-connection-backend

## Recent versions

- 11.0.1 (latest) — 2022-11-20
- 6.2.5 (angular8-ionic4-native5) — 2021-01-25
- 4.0.12 (ionic3-native4) — 2019-11-15
- 4.1.0 (ionic3-native5) — 2019-02-15
- 11.0.0 — 2022-10-23
- 10.0.0 — 2022-01-13
- 9.0.2 — 2021-11-30
- 9.0.1 — 2021-08-24
- 9.0.0 — 2021-05-26
- 8.1.4 — 2021-05-05
- 8.1.3 — 2021-02-27
- 8.1.2 — 2021-01-25
- 8.1.1 — 2020-08-29
- 6.2.4 — 2020-05-14
- 8.1.0 — 2020-05-14
- … 41 more at https://npm.io/package/ionic-native-http-connection-backend/versions

## README

# ionic-native-http-connection-backend

[![version](https://img.shields.io/npm/v/ionic-native-http-connection-backend.svg?style=flat-square)](http://npm.im/ionic-native-http-connection-backend)
[![MIT License](https://img.shields.io/npm/l/component-library.svg?style=flat-square)](http://opensource.org/licenses/MIT)

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`](https://github.com/ionic-team/cordova-plugin-ionic-webview) 
(and Cordova offers it via their [`cordova-plugin-wkwebview-engine`](https://github.com/apache/cordova-plugin-wkwebview-engine)). That causes requests that used to work just fine to fail with [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/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`](https://ionicframework.com/docs/native/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

```bash
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

```typescript
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](CONTRIBUTING.md)

## Troubleshooting

[TROUBLESHOOTING.md](TROUBLESHOOTING.md)

---
_Source: https://npm.io/package/ionic-native-http-connection-backend · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
