-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable custom http client like Axios #83
Comments
I have a structure where requests go over localhost for serverside calls and use a base url for client side calls. I have an axios interceptor that handles that currently, and it would be nice to be able to continue using that. I have another non technical reason to +1 this request this as well - when making the case for spraypaint for some corporate clients who currently use axios across multiple apps, even though it doesn't get them anything, not having the ability to slot axios in has come up in several meetings and it would be nice to put that argument to bed (and then not use it.) |
I want this feature too. it seems to make fetch api adaptable , as Line 107 in c4e085a
|
Started a PR (#90) for this thinking I needed it, but ended up not. If you get a chance to try it out in the wild let me know if it does/doesn't work for your use case(s) :) |
A very hacky solution, but in theory, since axios internally uses XMLHttpRequest and not const _fetch = window.fetch;
window.fetch = async function fetch(url, init) {
if (typeof url !== 'string') {
return _fetch(url, init);
}
const { method = 'get', headers } = init || {};
const res = await axios({
method,
url,
headers,
// ... anything else that you feel makes sense
responseType: 'arraybuffer',
});
const response = new Response(res.data, {
status: res.status,
statusText: res.statusText,
headers: res.headers,
});
// Object.defineProperty(response, 'url', { enumerable: true, value: url });
return response;
}; (I'll leave TypeScript types as an exercise to the user) Alternatively you can override spraypaint's |
I want to migrate our current app that uses Axios for api calls to spraypaint, is this still an issue? |
I see no issue, since you are moving from axios to plain spraypaint.js, but there's a PR to specify a fetcher, which you can hope get merged someday: #90 |
oh wow Feb 6th, yeh someday |
This one flew under my radar :) It's now on it. /cc @wadetandy |
Oh yeah i totally missed this as well, sorry about that. Will take a look. |
It would be really helpful to allow overwriting or mock the default http client. This is especially useful when the existing app is based on axios with many predefined axios interceptors and also when using server side rendering.
The text was updated successfully, but these errors were encountered: