Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 38x 38x 38x 38x 32x 32x 2x 14x 1x 1x | import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from '@environments/environment';
@Injectable({
providedIn: 'root',
})
export class DataService {
// API's base URL
private baseUrl = `${environment.apiUrl}/api/`;
constructor(private http: HttpClient) {}
// GET
get<T>(endpoint: string, options?: {params?: HttpParams, headers?: HttpHeaders}): Observable<T> {
return this.http.get<T>(`${this.baseUrl}${endpoint}`, { ...options, withCredentials: true});
}
// POST
post<T>(endpoint: string, body: unknown, options?: {params?: HttpParams, headers?: HttpHeaders}): Observable<T> {
return this.http.post<T>(`${this.baseUrl}${endpoint}`, body, {...options, withCredentials: true});
}
// PUT
put<T>(endpoint: string, body: unknown, options?: {params?: HttpParams, headers?: HttpHeaders}): Observable<T> {
return this.http.put<T>(`${this.baseUrl}${endpoint}`, body, {...options, withCredentials: true});
}
// PATCH
patch<T>(endpoint: string, body: unknown, options?: {params?: HttpParams, headers?: HttpHeaders}): Observable<T> {
return this.http.patch<T>(`${this.baseUrl}${endpoint}`, body, {...options, withCredentials: true});
}
// DELETE
delete<T>(endpoint: string, options?: {params?: HttpParams, headers?: HttpHeaders}): Observable<T> {
return this.http.delete<T>(`${this.baseUrl}${endpoint}`, {...options, withCredentials: true});
}
} |