New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ngx-endpoint

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-endpoint

Simplify Angular HTTP request API management

  • 0.3.2
  • next
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
258
decreased by-3.37%
Maintainers
1
Weekly downloads
 
Created
Source

npm version CircleCI quality gate quality gate - coverage

ngx-endpoint

Simplify Angular HTTP request API management.

Installing

npm install ngx-endpoint --save

Configuring

(1) create one EndpointService which extends the BaseEndpointService

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

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

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

Keywords

FAQs

Package last updated on 02 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc