Skip to content

Use page's actions without a from | submit programmatic/imperative form #13502

Answered by brunnerh
lsdebianchi asked this question in Q&A

You must be logged in to vote

I really do not recommend using actions like this. They return data specifically to be handled internally by SvelteKit. There are ways of handling the response manually (see docs here), but this will probably just unnecessarily complicate things.

The docs suggest to expose a JSON API, but I would prefer to keep my server side pattern consistent and keep the easy access to the RequestEvent goodies (things like: { request, cookies, fetch, params, locals } and so on).

The methods in +server like POST also receive a RequestEvent with all those things.

The code can by the way be fixed by removing the headers because otherwise the boundary will be missing. Browsers will automatically set the …

Replies: 3 comments 2 replies

You must be logged in to vote
0 replies
Answer selected by lsdebianchi

You must be logged in to vote
1 reply
@brunnerh

You must be logged in to vote
1 reply
@efreibe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants