I am designing Api endpoints in Angular using HttpClient. This is a single service class which will handle all the Rest calls, it will be called from other service classes(which are currently making Rest calls).
What is the best practice to make a generic Rest method.
getApi(url: string, options?: object): Observable<any> {
return this.http.get<any>(url, options).pipe(
catchError((error: HttpErrorResponse) => {
return throwError(error);
})
)
}
Or
getApi<T>(url: string, options?: object): Observable<T> {
return this.http.get<T>(url, options).pipe(
catchError((error: HttpErrorResponse) => {
return throwError(error);
})
)
}
Will any of the above be able to handle : HttpEvent, HttpResponse or other such response?
Should I make multiple methods to handle?
anywhen you cannot useT. - Ben