Created
July 11, 2021 12:08
-
-
Save panesardev/44b8569e2b6f00aac6a5eb810e019989 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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