vechain-sdk-js icon indicating copy to clipboard operation
vechain-sdk-js copied to clipboard

💡 [REQUEST] - Restore ability to inject custom "fetch" instance

Open ifavo opened this issue 6 months ago • 1 comments

Summary

In the previous SDK releases it was possible to provide a custom axios instance to HttpClient.

This made it possible to use existing modules like https://axios-cache-interceptor.js.org/, to add caching functionality for immutable http requests to nodes.

I used it to cache immutable http requests in redis and return data for quicker responses within an RPC proxy.

With beta 23 axios was replaced with fetch, which is a good alternative, but as regression it is now no longer possible to just inject the handler (in this case fetch) as dependency to achieve the same result.

I propose to add the same functionality with fetch, so its possible to add a custom fetch handler. It would also allow to send custom headers for authentification or other actions to node backends, if neccessary.

As a workaround it might be possible to provide a custom HttpClient but that would be an unnecessary overhead.

Basic Example

import fetch from 'node-fetch-cache';

const httpClient = new HttpClient(options.node, { fetch })
const thorClient = new ThorClient(httpClient)
const provider = new VeChainProvider(thorClient);

ifavo avatar Aug 01 '24 15:08 ifavo