What's a good way to refactor the api client to use SK's fetch? #6846
Replies: 1 comment
-
I'd love to see a good answer to this question. FWIW, here's the way I'm currently doing this. I'm not sure if a better pattern exists, especially with the latest changes. But the pattern I'm using is a remnant of the now deceased Basically, I'm creating the // routes/+layout.ts
export const load: LayoutLoad = async ({ fetch, data }) => {
const api = createApi({
loadFetch: fetch,
token: data.accessToken,
roleId: data.user.roleId,
});
return {
api: api,
};
}; // routes/dogs/+page.ts
export const load: PageLoad = async ({ parent }) => {
const parentStuff = await parent();
const dogs = await parentStuff.api.dogs.findAll();
return { dogs };
}; The Also, here are some issues that might be relevant to this discussion: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using a very similar approach in my app to this one: Sveltekit-realworld to make requests to my REST API. But, since the latest changes, I'm seeing weird behaviors in my app and some people have suggested to use the Sveltekit provided fetch to do my server-side fetches. I was just wondering what might be a good idea to implement that?
Maybe something like this but it gets kind of redundant:
Beta Was this translation helpful? Give feedback.
All reactions