@spreadmonitor/network
TypeScript icon, indicating that this package has built-in type declarations

14.0.0 • Public • Published

Network Module

This modules is an universal network layer.

Installation

Install the package

npm install @spreadmonitor/network

NOTE: This package has a peer-dependency of some @angular/* packages..

Import the module

After successful install, import the NetworkModule into your root NgModule.

import { NetworkModule, NetworkAuthService } from '@spreadmonitor/network';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    HttpClientModule,
    NetworkModule.forRoot({
      /**
       * Base endpoint for the API.
       * Notice there is no slash in the end.
       */
      baseUrl: 'https://api.your-beautiful-api.com',
      /**
       * Type of the auth method.
       *
       * Valid values are 'basic' or 'bearer'.
       */
      authType: 'bearer',
    })
  ],
  providers: [
    /**
     * AuthService is your own implementation, which must have a
     *  - token: string property
     *  - authenticated: boolean property
     */
    { provide: NetworkAuthService,  useExisting: AuthService, }
  ]
  bootstrap: [AppComponent],
})
export class AppModule {}

Usage

@Component()
class CustomComponent {

  constructor(
    private network: NetworkService;
  );

  public getSomething(path: string) {
    this.network.get(path, { queryParamOne = 4, boolean: true, stringValue: 'yay' }).subscribe(response => {
      console.log('Response arrived', response);
    });
  }

  public postSomething(path: string) {
    this.network.get(path, { myData: 5 } { queryParamOne = 4, boolean: true, stringValue: 'yay' }).subscribe(response => {
      console.log('Payload sent, response arrived', response);
    });
  }
}

Contributing

Before contributing to this package please make sure you have read our CONTRIBUTING guide.

Readme

Keywords

none

Package Sidebar

Install

npm i @spreadmonitor/network

Weekly Downloads

0

Version

14.0.0

License

SEE LICENSE IN LICENSE

Unpacked Size

117 kB

Total Files

27

Last publish

Collaborators

  • nonameprovided
  • sp-ci-write