Skip to content

Instantly share code, notes, and snippets.

@panesardev
Created July 11, 2021 12:08
Show Gist options
  • Save panesardev/44b8569e2b6f00aac6a5eb810e019989 to your computer and use it in GitHub Desktop.
Save panesardev/44b8569e2b6f00aac6a5eb810e019989 to your computer and use it in GitHub Desktop.
export class HttpService<T> {
constructor(
private http: HttpClient,
private url: string,
) {
this.url = this.url.endsWith('/') ? this.url : this.url + '/';
}
findAll(): Observable<T[]> {
return this.http.get<T[]>(this.url);
}
find(id: string): Observable<T> {
return this.http.get<T>(this.url + id);
}
create(t: T): Observable<T> {
return this.http.post<T>(this.url, t);
}
update(t: T): Observable<T> {
return this.http.put<T>(this.url + t['id'], t);
}
delete(id: string): Observable<any> {
return this.http.delete<any>(this.url + id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment