https://github.com/billcheng/a4-http
Angular 4 Enhanced Http Service with Spinner & etc
https://github.com/billcheng/a4-http
angular angular2 angular4 http spinner
Last synced: 9 months ago
JSON representation
Angular 4 Enhanced Http Service with Spinner & etc
- Host: GitHub
- URL: https://github.com/billcheng/a4-http
- Owner: billcheng
- Created: 2017-06-17T04:56:06.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-17T05:56:32.000Z (almost 9 years ago)
- Last Synced: 2025-07-01T05:03:16.994Z (9 months ago)
- Topics: angular, angular2, angular4, http, spinner
- Language: TypeScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# a4-http
Angular 4 Enhanced Http Service
# How-To
## Install
```
npm install a4-http
```
## app.module.ts
1. Add ```HttpModule``` to imports of the ```app.module.ts```.
```typescript
...
import { HttpModule } from 'a4-http';
...
@NgModule({
declarations: [
AppComponent
],
imports: [
...,
HttpModule,
...
],
...
})
```
## Inject the service
```typescript
constructor(private http: HttpService) { }
```
## Show/Hide the Spinner
```typescript
this.http.setSpinner(
() => {
... // show spinner code
}, () => {
... // hide spinner code
}
);
```
## get, post, put, patch & delete
```typescript
public get(url: string, showSpinner?: boolean): Observable;
public get(url: string, options?: any, showSpinner?: boolean): Observable;
public post(url: string, body: any, showSpinner?: boolean): Observable;
public post(url: string, body: any, options?: any, showSpinner?: boolean): Observable;
public put(url: string, body: any, showSpinner?: boolean): Observable;
public put(url: string, body: any, options?: any, showSpinner?: boolean): Observable;
public patch(url: string, body: any, showSpinner?: boolean): Observable;
public patch(url: string, body: any, options?: any, showSpinner?: boolean): Observable;
public delete(url: string, showSpinner?: boolean): Observable;
public delete(url: string, options?: any, showSpinner?: boolean): Observable;
```
## redirect when error
```typescript
this.http.setRedirect({
'-1': '/error',
0: '/signin',
401: '/signin',
403: '/signin'
});
```
1. Redirect to ```/signin``` if http status is 0, 401 or 403.
1. '-1' is the default route if there is an error... '-1' is optional.