add optional adaptar

This commit is contained in:
liangping 2024-01-11 13:55:25 +08:00
parent 73f36c64b4
commit ef39c448cb

View File

@ -20,7 +20,7 @@ export class BaseRestClient<R extends AbstractRegistry> {
this.endpoint = endpoint; this.endpoint = endpoint;
this.registry = registry; this.registry = registry;
} }
async request<T>(request: Request<T>, args: Record<string, any>, query = '', adapter: (source: any) => T = undefined) { async request<T>(request: Request<T>, args: Record<string, any>, query = '', adapter?: (source: any) => T ) {
let url = `${request.url.startsWith("http")?'':this.endpoint}${request.url}${query}`; let url = `${request.url.startsWith("http")?'':this.endpoint}${request.url}${query}`;
Object.keys(args).forEach((k) => { Object.keys(args).forEach((k) => {
url = url.replace(`{${k}}`, args[k] || ''); url = url.replace(`{${k}}`, args[k] || '');