The Core SDK provides foundational functionality leveraged by dependent Kontent.ai SDKs, such as @kontent-ai/delivery-sdk
and @kontent-ai/management-sdk
.
The SDK includes a default implementation of the HttpService
and HttpAdapter
components, which handle HTTP requests to the Kontent.ai APIs.
These implementations are designed to work out-of-the-box but are also fully customizable. Developers may replace them with custom versions to extend or override the default behavior, depending on specific application requirements.
The HttpService
comes with several built-in capabilities, such as:
- Retry policies
- Request validation
- Automatic header and tracking management
- Kontent.ai-specific error extraction
To customize these behaviors entirely, you can replace the HttpService
with your own implementation.
However, if your goal is to retain the core features (e.g., retry policies, request validation) and only swap out the underlying HTTP client, you can do so by supplying a custom HttpAdapter
to the getDefaultHttpService
method.
Below is an example demonstrating how to provide your own HTTP client by implementing a custom HttpAdapter
:
const httpService = await getDefaultHttpService({
adapter: {
requestAsync: async (options) => {
// Execute the request using your custom HTTP client
return {
isValidResponse: <true | false>,
responseHeaders: <arrayOfHeaders>,
status: <statusCode>,
statusText: <statusText>,
toJsonAsync: async () => <responseInJson>,
toBlobAsync: async () => <responseInBlob>,
};
},
},
});
This approach gives you fine-grained control over how requests are made, while still benefiting from the core service's additional functionalities.