Currently, the fetch client is cross-fetch which is fine in most situations, but in some cases, it can be very problematic. Personally, I'm trying to use web3.js on Cloudflare Workers which has a custom fetch client. In other cases, like React Native, the library may also not work, see: https://github.com/solana-labs/solana/issues/22421
My point is that there should be an option to use another fetch function.
Proposed Solution
Currently, there is a Middleware option in the Connection constructor. The issue with this middleware is that it's very limited as we have to use the provided fetch function as a callback. I propose to have a FetchMiddleware function like that:
const fetchMiddleware = async (url, options): Promise<Response> => {
// Your code, but here's how you would use it:
return await fetch(url, options)
}
It really shouldn't be hard to implement it. I can probably do it, but I prefer to wait for feedback.
Problem
Currently, the fetch client is
cross-fetch
which is fine in most situations, but in some cases, it can be very problematic. Personally, I'm trying to use web3.js on Cloudflare Workers which has a custom fetch client. In other cases, like React Native, the library may also not work, see: https://github.com/solana-labs/solana/issues/22421My point is that there should be an option to use another fetch function.
Proposed Solution
Currently, there is a Middleware option in the Connection constructor. The issue with this middleware is that it's very limited as we have to use the provided
fetch
function as a callback. I propose to have aFetchMiddleware
function like that:It really shouldn't be hard to implement it. I can probably do it, but I prefer to wait for feedback.