Get Started
Custom HTTP Client
The TypeScript SDK makes API calls using an HTTPClient that wraps the native Fetch API. This client is a thin wrapper around fetch
and provides the ability to attach hooks around the request lifecycle that can be used to modify the request or handle errors and response.
The HTTPClient
constructor takes an optional fetcher
argument that can be used to integrate a third-party HTTP client or when writing tests to mock out the HTTP client and feed in fixtures.
The following example shows how to use the beforeRequest
hook to to add a custom header and a timeout to requests and how to use the requestError
hook to log errors:
Was this page helpful?