-
-
Notifications
You must be signed in to change notification settings - Fork 531
Svelte custom fetch #1125
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
Comments
This is a great idea! I’m actually working on building out more of a docs site right now, and framework-specific examples should definitely be added. |
But also there probably are some caveats with language-specific things. For example, in React/React Router, there are loaders that can be used to load data on route change (which can be handy for things like auth), however, this is incompatible with But again, it would still help to have framework examples along with notes about what does/doesn’t work well for each framework (but as a general rule, openapi-fetch will probably work the exact same way a typed GraphQL client will) |
drwpow/openapi-fetch#51 partially handles this by allowing you to override the default global |
Edit: I’ve just transferred the issue (just learned you could do that!). |
It's currently not possible to pass const { response } = await POST("/auth/login", {
body: form.data,
fetch,
}); And it seems necessary, because the |
@pkb-pmj I have not used this library (yet), but I guess you could do createClient<paths>({ baseUrl: "https://myapi.dev/v1/", fetch }) in your load function and create a client everywhere you want to fetch? |
I can also do it e.g. in export const handle = async ({ event, resolve }) => {
const client = createClient<paths>({
fetch: event.fetch,
baseUrl: "/api",
});
event.locals.GET = client.GET;
event.locals.PATCH = client.PATCH;
event.locals.POST = client.POST;
event.locals.PUT = client.PUT;
return await resolve(event);
}; But I guess I don't want to create a new client on every request, when it's very easy to modify the client to accept custom per-request |
Added an example to the docs that uses the custom fetcher. To @pkb-pmj’s suggestion of putting in
In most instances, yes, that’d probably be a concern. But I recently added benchmarks and the |
@drwpow ok, I didn't think of that lol const client = createServerClient(fetch);
const fact = await client.GET("/fact", {
params: {
query: { max_length: 500 },
},
}); Not much different than using const fact = await locals.GET("/fact", {
params: {
query: { max_length: 500 },
},
}); Or my custom version: const fact = await GET("/fact", {
fetch,
params: {
query: { max_length: 500 },
},
}); which is objectively better in a way that realistically doesn't matter as you said, so it's a question of preference? |
Svelte provides a custom fetch in their load functions which you have to use in order to use SSR and their middleware handlers.
For this library Svelte is listed as supported, but I can't figure out how this Svelte fetch is used. Are there examples? Or is this underway?
The text was updated successfully, but these errors were encountered: