a4-http
v0.0.3
Published
Angular 4 Enhanced Http Service
Downloads
3
Readme
a4-http
Angular 4 Enhanced Http Service
How-To
Install
npm install a4-http
app.module.ts
- Add
HttpModule
to imports of theapp.module.ts
.
...
import { HttpModule } from 'a4-http';
...
@NgModule({
declarations: [
AppComponent
],
imports: [
...,
HttpModule,
...
],
...
})
Inject the service
constructor(private http: HttpService) { }
Show/Hide the Spinner
this.http.setSpinner(
() => {
... // show spinner code
}, () => {
... // hide spinner code
}
);
get, post, put, patch & delete
public get(url: string, showSpinner?: boolean): Observable<Response>;
public get(url: string, options?: any, showSpinner?: boolean): Observable<Response>;
public post(url: string, body: any, showSpinner?: boolean): Observable<Response>;
public post(url: string, body: any, options?: any, showSpinner?: boolean): Observable<Response>;
public put(url: string, body: any, showSpinner?: boolean): Observable<Response>;
public put(url: string, body: any, options?: any, showSpinner?: boolean): Observable<Response>;
public patch(url: string, body: any, showSpinner?: boolean): Observable<Response>;
public patch(url: string, body: any, options?: any, showSpinner?: boolean): Observable<Response>;
public delete(url: string, showSpinner?: boolean): Observable<Response>;
public delete(url: string, options?: any, showSpinner?: boolean): Observable<Response>;
redirect when error
this.http.setRedirect({
'-1': '/error',
0: '/signin',
401: '/signin',
403: '/signin'
});
- Redirect to
/signin
if http status is 0, 401 or 403. - '-1' is the default route if there is an error... '-1' is optional.