@spreadmonitor/network
v18.0.1
Published
Universal network layer for our Angular applications.
Downloads
42
Readme
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.