35 lines
859 B
TypeScript
35 lines
859 B
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class ServicesService {
|
|
|
|
private baseUrl = 'https://your-api-url.com/api'; // Set your base URL
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
// 🔹 GET
|
|
get<T>(endpoint: string): Observable<T> {
|
|
return this.http.get<T>(`${this.baseUrl}/${endpoint}`);
|
|
}
|
|
|
|
// 🔹 POST
|
|
post<T>(endpoint: string, data: any): Observable<T> {
|
|
return this.http.post<T>(`${this.baseUrl}/${endpoint}`, data);
|
|
}
|
|
|
|
// 🔹 PUT
|
|
put<T>(endpoint: string, data: any): Observable<T> {
|
|
return this.http.put<T>(`${this.baseUrl}/${endpoint}`, data);
|
|
}
|
|
|
|
// 🔹 DELETE
|
|
delete<T>(endpoint: string): Observable<T> {
|
|
return this.http.delete<T>(`${this.baseUrl}/${endpoint}`);
|
|
}
|
|
|
|
}
|