src/app/shared/widgets/widgetframe/widgetframe.service.ts
Service to provide common json request methods with AuthHttp
Widget inputs |
Widget outputs |
Properties |
|
Methods |
constructor(authHttp: HttpClient)
|
||||||
Parameters :
|
getData | ||||||||||||
getData(inputurl: , options?: any)
|
||||||||||||
GET with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error.
Parameters :
Returns :
Observable<any>
Observable of json response |
getDataWithResponseType | |||||||||
getDataWithResponseType(inputurl: , resType: )
|
|||||||||
GET with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error.
Parameters :
Returns :
Observable<any>
Observable of json response |
patchData | |||||||||
patchData(inputurl: , body: )
|
|||||||||
PATCH with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error.
Parameters :
Returns :
Observable<any>
Observable of json response |
postData | ||||||||||||||||
postData(inputurl: , body: , options?: any)
|
||||||||||||||||
POST with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error.
Parameters :
Returns :
Observable<any>
Observable of json response |
putData | ||||||||||||||||
putData(inputurl: string, body: any, options?: any)
|
||||||||||||||||
PUT with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error.
Parameters :
Returns :
Observable<any>
Observable of json response |
Public authHttp |
authHttp:
|
Type : HttpClient
|
import { tap } from "rxjs/operators";
import { Injectable } from "@angular/core";
import { NEVER, Observable } from "rxjs";
import { HttpClient } from "@angular/common/http";
import { ProgressbarService } from "../../components/progressbar/progressbar.service";
/**
* Service to provide common json request methods with AuthHttp
*
*/
@Injectable()
export class WidgetframeService {
constructor(public authHttp: HttpClient) {}
/**
* GET with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error.
* @param inputurl Url to json resource
* @returns Observable of json response
*/
getData(inputurl, options?: any): Observable<any> {
if (!inputurl) {
console.error("Inputurl can not be null");
return NEVER;
}
return this.authHttp.get(inputurl, options);
}
/**
* GET with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error.
* @param inputurl Url to json resource
* @param resType the response type
* @returns Observable of json response
*/
getDataWithResponseType(inputurl, resType): Observable<any> {
if (!inputurl) {
console.error("Inputurl can not be null");
return NEVER;
}
const options = {
responseType: resType,
};
return this.authHttp.get(inputurl, options as any);
}
/**
* PUT with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error.
* @param inputurl Url to json
* @returns Observable of json response
*/
putData(inputurl: string, body: any, options?: any): Observable<any> {
if (!inputurl) {
console.error("Inputurl can not be null");
return NEVER;
}
return this.authHttp.put(inputurl, body, options);
}
/**
* POST with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error.
* @param inputurl Url to json
* @param body json Payload
* @returns Observable of json response
*/
postData(inputurl, body, options?: any): Observable<any> {
if (!inputurl) {
console.error("Inputurl can not be null");
return NEVER;
}
return this.authHttp.post(inputurl, body, options);
}
/**
* DELETE with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error. Should be replaced by using deletes without body,
* since it does not conform with RFC standard
* @param inputurl Url to json
* @param body json Payload
* @returns Observable of json response
*/
deleteData(inputurl, body = null): Observable<any> {
if (!inputurl) {
console.error("Inputurl can not be null");
return NEVER;
}
const options = {
headers: [],
body,
};
return this.authHttp.delete(inputurl, options as any);
}
/**
* PATCH with AuthHttp. Starts Progressbar before start and and stops Progressbar on finish and error.
* @param inputurl Url to json
* @param body json Payload
* @returns Observable of json response
*/
patchData(inputurl, body): Observable<any> {
return this.authHttp.patch(inputurl, body);
}
}