mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
improve api interface
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { HttpContext, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpResponse, HttpErrorResponse } from '@angular/common/http';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { tap, shareReplay, catchError } from "rxjs/operators";
|
||||
import { Observable, of } from "rxjs";
|
||||
|
||||
@@ -11,8 +11,7 @@ export class HttpServiceService {
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
|
||||
put(url: string, body: any | null, options: Options): Observable<any> {
|
||||
put<T>(url: string, body: any | null, options: Options): Observable<T> {
|
||||
return this.http.put(url, body, options as any).pipe(
|
||||
tap((response) => {
|
||||
// Handle success response if needed
|
||||
@@ -24,20 +23,35 @@ export class HttpServiceService {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
post<T>(url: string, body: any | null, options: Options): Observable<T> {
|
||||
return this.http.post(url, body, options as any).pipe(
|
||||
tap((response) => {
|
||||
// Handle success response if needed
|
||||
}),
|
||||
catchError((error) => {
|
||||
// Handle error response if needed
|
||||
return of(error);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
get<T>(url: string, options: Options): Observable<T> {
|
||||
return this.http.get(url, options ).pipe(
|
||||
tap((response) => {
|
||||
// Handle success response if needed
|
||||
}),
|
||||
catchError((error) => {
|
||||
// Handle error response if needed
|
||||
return of(error);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
interface Options {
|
||||
headers?: HttpHeaders | {
|
||||
[header: string]: string | string[];
|
||||
};
|
||||
context?: HttpContext;
|
||||
observe?: 'body';
|
||||
params?: HttpParams | {
|
||||
[param: string]: string | number | boolean | ReadonlyArray<string | number | boolean>;
|
||||
};
|
||||
reportProgress?: boolean;
|
||||
responseType?: 'arraybuffer';
|
||||
withCredentials?: boolean;
|
||||
headers?: HttpHeaders
|
||||
params?: HttpParams
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user