# ngx-endpoint

> Simplify Angular HTTP request API management

Latest version **0.3.2** (published 2018-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-endpoint
pnpm add ngx-endpoint
yarn add ngx-endpoint
bun add ngx-endpoint
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2018-11-02 |
| First published | 2018-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 213 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Cotton Hou |
| Maintainers | imcotton |
| Keywords | Angular, interceptor |

## Links

- npm: https://www.npmjs.com/package/ngx-endpoint
- Repository: https://github.com/imcotton/ngx-endpoint
- Homepage: https://github.com/imcotton/ngx-endpoint#readme
- Issues: https://github.com/imcotton/ngx-endpoint/issues
- npm.io page: https://npm.io/package/ngx-endpoint

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.9.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2018-11-02
- 0.3.2-0 — 2018-11-02
- 0.3.1 — 2018-10-30
- 0.3.1-0 — 2018-10-29
- 0.3.0 — 2018-10-29
- 0.3.0-0 — 2018-10-29
- 0.2.2 — 2018-10-28
- 0.2.2-rc.0 — 2018-10-28
- 0.2.1 — 2018-10-27
- 0.2.0 — 2018-10-25
- 0.1.2 — 2018-10-23
- 0.1.1 — 2018-10-23
- 0.1.0 — 2018-10-22
- 0.0.3 — 2018-10-21
- 0.0.2 — 2018-10-21
- … 1 more at https://npm.io/package/ngx-endpoint/versions

## README

[![npm version](https://badgen.net/npm/v/ngx-endpoint)](https://www.npmjs.com/package/ngx-endpoint)
[![CircleCI](https://circleci.com/gh/imcotton/ngx-endpoint.svg?style=shield)](https://circleci.com/gh/imcotton/ngx-endpoint)
[![quality gate](https://sonarcloud.io/api/project_badges/measure?project=imcotton_ngx-endpoint&metric=alert_status)](https://sonarcloud.io/dashboard?id=imcotton_ngx-endpoint)
[![quality gate - coverage](https://sonarcloud.io/api/project_badges/measure?project=imcotton_ngx-endpoint&metric=coverage)](https://sonarcloud.io/component_measures?id=imcotton_ngx-endpoint&metric=coverage)

# ngx-endpoint

### Simplify **Angular** HTTP request API management.





## Installing

```bash
npm install ngx-endpoint --save
```





## Configuring

### **(1)** create one `EndpointService` which `extends` the `BaseEndpointService`

```typescript
import { Injectable } from '@angular/core';
import { BaseEndpointService } from 'ngx-endpoint';



@Injectable({
  providedIn: 'root',          // <---- only for Angular v6+, remove it on v4 or v5
})
export class EndpointService extends BaseEndpointService {

  readonly api = this.booking('/api');   // <---- register as prefix

  readonly gitLab = this.booking('https://gitlab.com/api/v4');   // <---- another one



  protected onInit () {

    this.api.headers.add({
      'X-Powered-By': 'NgxEndpoint',    // <---- leaves small ink on future calling
    });

  }

}
```



### **(2)** wire up everything together

```typescript
import { HttpClientModule } from '@angular/common/http';

import { NgxEndpointModule, BaseEndpointService } from 'ngx-endpoint';

import { EndpointService } from 'app/endpoint-service';



@NgModule({
  imports: [
    HttpClientModule,

    NgxEndpointModule,
  ],
  providers: [

    // EndpointService,   <---- need this if on Angular v4 or v5

    { provide: BaseEndpointService, useExisting: EndpointService },

  ],
  bootstrap: [ AppComponent ],
})
export class AppModule { }
```



### **(3)** let's ues this `api` in real service

```typescript
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { EndpointService } from 'app/endpoint-service';



@Injectable()
export class MyService {

  constructor (
    private readonly http: HttpClient,
    private readonly endpoint: EndpointService,   // <---- inject EndpointService
  ) {
  }


  private readonly api = this.endpoint.api;   // <---- retrieve that api instance


  getInfo () {
    return this.http.get(this.api.to('/info'));   // <---- auto prefixed
  }

  setOAuth (token: string) {
    this.api.auth.OAuth2(token);   // <---- assign OAuth2 token
  }

  setJWT (token: string) {
    this.api.auth.JWT(token);   // <---- assign JWT token
  }

  setBasic (user: string, pass: string) {
    this.api.auth.basic(user, pass);   // <---- assign Basic Auth credentials
  }

}
```



### that's it.





## License

### the MIT

---
_Source: https://npm.io/package/ngx-endpoint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
