I have a vision to develop an ultra-generic API Resolver for my application. The goal is to have all "GET" requests, with potential extension to other verbs in the future, utilize this resolver. I aim to pass the URL and request verb to the resolver, allowing it to handle the function call accordingly.
This resolver will be applied to any Angular route definition containing a parameter named "id", with the ability to specify the desired return type.
Although the theoretical idea sounds promising, it is currently not functional due to issues with implementing the interface through Angular.
export class ApiResolve<T> implements Resolve<T> {
constructor(private _httpClient: HttpClient) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot, requestUrl: string, requestVerb: 'get'): Observable<T> {
return this._httpClient.request<T>(requestVerb, `${requestUrl}/${route.data['id']}`);
}
}
{ path: `user/:id`, component: UserComponent, resolve: { user: ApiResolver<User>('api.com/users', 'get') } }