1.0.7 • Published 4 years ago

@ferhado/http v1.0.7

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Angular HttpClient

Installation

npm install @ferhado/http --save

Usage Example

app.module.ts

import { HttpModule } from '@ferhado/http';

@NgModule({
  // ...
  
  imports: [
    // ...
    HttpModule.forRoot({
      // Optional, all requests will begin with this prefix
      requestUrlPrefix: 'https://jsonplaceholder.typicode.com/'
    })
  ],
  bootstrap: [AppComponent]
})

export class AppModule { }

app.component.ts

import { Component, OnInit } from '@angular/core';
import { HttpService } from '@ferhado/http';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styles: []
})

export class AppComponent implements OnInit {
  constructor(private http: HttpService) { }

  // Possible usage
  // this.http.post(url)
  // this.http.post(url, callback)
  // this.http.post(url, params, callback)
  // this.http.post(url, params, options, callback)

  ngOnInit() {
    this.http.post("/posts",
      // params: object | fromData
      {
        test: "Test"
      },
      // options
      {
        useUrlPrefix?: boolean, // set to false to ignore url prefix from config
        headers?: any,
        observe?: 'body' | 'events' | 'response',
        reportProgress?: boolean,
        responseType?: 'arraybuffer' | 'blob' | 'json' | 'text',
        withCredentials?: boolean,
      },
      // callback
      (response) => {
        console.log(response);
      });
  }

}
1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.0

4 years ago

1.0.1

4 years ago