@kimaya/ngx-http-service v1.0.11
HttpHandler
This project was generated with Angular CLI version 8.1.0.
How Install
npm install @kimaya/ngx-http-service
Dependency
You need to install dependencies manually
CookieStorage this is being used to store all cookies in this library. AuthService this is being used for checking and fetching auth related settings.
Plug into your application
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HttpServiceModule } from 'ngx-http-service';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpServiceModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
How to use
Inject into your Component or Service.
import { Component } from '@angular/core';
import { HttpService } from 'ngx-http-service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(private httpService: HttpService) {
}
}
HttpService Configure
User can configure some of keys for auth service as per project requirements.
User need to set HttpServiceConstants keys for usages.
Need to set serverUrl .This will be used to hit api using httpService used as host for all default api
ServerUrl is host
Keys | Required | Default Value | Usage |
---|---|---|---|
serverUrl | true | null | used to store default host for all api end point which passed to HttpService functions |
headers | false | {} | Provide extra headers for all Http request including multipart request |
Methods
get(endPoint: string, params?: object, body?: object, contentType?: string, backendUrl?: string ): Observable;
this.httpService.get(endPoint).subscribe();
to call http get method. In this method service will automatically append serverUrl from constant (host) and endPoint parameter.
- endPoint: http api end point without host
- params: to set in param header optional
- body: to set in body header optional
- contentType: to set in content type header optional
- backendUrl: if you want to change host pass this parament optional
getFromUrl(url: string, params?: object, body?: object, contentType?: string): Observable;
this.httpService.getFromUrl(endPoint).subscribe();
to call http get method. In this method service will not append serverUrl from constant (host) and will hit api based url you pass.
- url: http api url with host and end point
- params: to set in param header optional
- body: to set in body header optional
- contentType: to set in content type header optional
getFromUrlWithoutHeader(url: string): Observable;
this.httpService.getFromUrlWithoutHeader(url).subscribe();
to call http get method. In this method, service will not add default header setting for http call.
- url: http api url with host and end point
- headers: HttpHeader- Custom Headers can be added.
post(endPoint: string, requestBody: object, params?: object, body?: object, contentType?: string, backendUrl?: string ): Observable;
this.httpService.post(endPoint, requestBody).subscribe();
to call http post method. In this method service will automatically append serverUrl from constant (host) and endPoint parameter.
- endPoint: http api end point without host
- requestBody: request body in json
- params: to set in param header optional
- body: to set in body header optional
- contentType: to set in content type header optional
- backendUrl: if you want to change host pass this parameter optional
postFromUrl(url: string, requestBody: object, params?: object, body?: object, contentType?: string): Observable;
this.httpService.postFromUrl(url, requestBody).subscribe();
to call http post method. In this method service will not append serverUrl from constant (host) and will hit api based url you pass.
- url: http api url with host and end point
- requestBody: request body in json
- params: to set in param header optional
- body: to set in body header optional
- contentType: to set in content type header optional
postFromUrlWithoutHeader(url: string, requestBody: object): Observable;
this.httpService.postFromUrlWithoutHeader(url, requestBody).subscribe();
to call http post method. In this method, service will not add default header setting for http call.
- url: http api url with host and end point
- requestBody: request body in json
- headers: HttpHeader- Custom Headers can be added.
putFromUrlWithoutHeader(url: string, requestBody: object): Observable;
this.httpService.putFromUrlWithoutHeader(url, requestBody).subscribe();
to call http put method. In this method, service will not add default header setting for http call.
- url: http api url with host and end point
- requestBody: request body in json
- headers: HttpHeader- Custom Headers can be added.
delete(endPoint: string, params?: object, body?: object, contentType?: string, backendUrl?: string ): Observable;
this.httpService.delete(endPoint).subscribe();
to call http delete method. In this method service will automatically append serverUrl from constant (host) and endPoint parameter.
- endPoint: http api end point without host
- params: to set in param header optional
- body: to set in body header optional
- contentType: to set in content type header optional
- backendUrl: if you want to change host pass this parameter optional
deleteFromUrl(url: string, params?: object, body?: object, contentType?: string): Observable;
this.httpService.deleteFromUrl(endPoint).subscribe();
to call http delete method. In this method service will not append serverUrl from constant (host) and will hit api based url you pass.
- url: http api url with host and end point
- params: to set in param header optional
- body: to set in body header optional
- contentType: to set in content type header optional
deleteFromUrlWithoutHeader(url: string): Observable;
this.httpService.deleteFromUrlWithoutHeader(url).subscribe();
to call http delete method. In this method, service will not add default header setting for http call.
- url: http api url with host and end point
- headers: HttpHeader- Custom Headers can be added.
multipart(endPoint: string, formData: FormData, methodType: HttpMethodTypes = HttpMethodTypes.GET, backendUrl?: string, responseType: HttpResponseTypes = HttpResponseTypes.json, authKey: string = 'Authorization'): Observable;
this.httpService.multipart(endPoint, formData).subscribe();
to call http method for multipart. In this method service will automatically append serverUrl from constant (host) and endPoint parameter.
- endPoint: string
- formData: FormData
- methodType: HttpMethodTypes = HttpMethodTypes.GET // default get method
- backendUrl: string optional
- responseType: HttpResponseTypes = HttpResponseTypes.json // default JSON type
- httpHeaders: HttpHeader = null // default null
- authKey: string = 'Authorization'
multipartFromUrl(url: string, formData: FormData, methodType: HttpMethodTypes = HttpMethodTypes.GET, backendUrl: string, responseType: HttpResponseTypes = HttpResponseTypes.json, authKey: string = 'Authorization'): Observable;
this.httpService.multipartFromUrl(endPoint, formData).subscribe();
to call http method for multipart. In this method, service will not add default header setting for http call.
- url: string
- formData: FormData
- methodType: HttpMethodTypes = HttpMethodTypes.GET // default get method
- responseType: HttpResponseTypes = HttpResponseTypes.json // default JSON type
- httpHeaders: HttpHeader = null // default null
- authKey: string = 'Authorization'
Enums
We can use this enum values to pass parameters for multipart methods.
HttpResponseTypes
enum HttpResponseTypes {
'blob' = 'blob',
'json' = 'json',
'arraybuffer' = 'arraybuffer'
}
HttpMethodTypes
enum HttpMethodTypes {
'GET' = 'GET',
'POST' = 'POST',
'PUT' = 'PUT'
}
For more Information
you can contact on kumarganesh088@gmail.com
2 years ago
2 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago