FetchClient
A fetch wrapper to make authorized requests
Overview
The overwhelming majority of tokens are minted to make authenticated requests to resource servers. The FetchClient is a fetch wrapper to ease signing Request instances with an Authorization header.
Example
typescript
const fetchClient = new FetchClient(orchestrator);
const response = await fetchClient.fetch('/api/messages');
const data = await response.json();
// Do something with data...Features
Bearertoken authorizationDPoPtoken authorization (withdpop-nonceretry and caching)insufficient_user_authenticationstep-up authentication support401auto-retry429auto-retry with exponential backoff orretry-afterheader support
Extensibility
To change the default behavior or add additional capabilities, simply extend the FetchClient class:
typescript
export class MyFetchClient extends FetchClient {
defaultHeaders = { 'foo': 'bar' };
// Updates `429` retry delay to always be 1s
protected getRetryDelay(response: Response, request: APIRequest): number {
return 1000;
}
protected async processResponse(response: Response, request: APIRequest) {
// Send analytics data to server
await sendData(response);
super.processResponse(response, request);
}
}