import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { firstValueFrom } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class HttpService { public constructor(private httpClient: HttpClient) { } public async get(url: string): Promise { return this.request(url, 'get'); } public async post(url: string, body?: any): Promise { return this.request(url, 'post', body); } public async put(url: string, body?: any): Promise { return this.request(url, 'put', body); } public async delete(url: string): Promise { return this.request(url, 'delete'); } private async request(url: string, method: 'get' | 'post' | 'put' | 'delete', body?: any): Promise { const headers = { 'Accept': 'application/json', 'Content-Type': 'application/json' }; switch (method) { case 'post': return firstValueFrom(this.httpClient.post(url, body, { headers })); case 'put': return firstValueFrom(this.httpClient.put(url, body, { headers })); case 'delete': return firstValueFrom(this.httpClient.delete(url, { headers })); default: return firstValueFrom(this.httpClient.get(url, { headers })); } } }