Skip to main content
Version: 4.x.x

Global Defaults


Use global defaults for request

To significantly limit the setup of our application, we can add global configs. To get the greatest flexibility in the context of the created configurations in larger and more complex applications, they are added through callbacks based on request data. Thanks to this, we can, for example, make one default configuration for requests using the get method and another for the others.

It is worth remembering that global configurations are overwritten by request settings, so the options that we set will be applied only to requests that do not have them specified in their options.


Example

export const client = new Client({ url }).setRequestDefaultOptions((requestOptions) => {
if (requestOptions.method === "GET") {
return {
deduplicate: true,
cacheTime: 20000,
retry: 3,
};
}

return {
deduplicate: false,
cache: false,
retry: 0,
};
});

Add your own key mappers

Data and requests made within our library are organized by keys. Each key is generated from request metadata such as parameters, query parameters, endpoint and method. They can be replaced by the way you choose to segregate and organize data with your own key mappers. Key must be a string value.

client.setQueueKeyMapper((request) => `Custom_Key_${request.method}_${request.endpoint}`);
client.setAbortKeyMapper((request) => `Abort_Key_${request.method}_${request.endpoint}`);
client.setCacheKeyMapper((request) => `Abort_Key_${request.method}_${request.endpoint}`);
client.setEffectKeyMapper((request) => `Abort_Key_${request.method}_${request.endpoint}`);