which type of parameter should I pass in GET/POST in server side script? #8675
-
I am wondering which type of data can be used for Load data in sveltekit ? When I see the GET/POST function in +server.js/+page.server.js .. it has request, response, fetch, url , etc. And i can not find proper documents for these parameter usage cases. I need 'request' / 'response' object sometimes and 'fetch' sometimes in +server.js . How should these parameters be discriminated specially in server side script ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Here is the documentation regarding the https://kit.svelte.dev/docs/types#public-types-requestevent It will look something like this: export const load = ({ cookies, fetch, locals, params, request, setHeaders }) => {
// ...
} Only the endpoint in https://kit.svelte.dev/docs/hooks#server-hooks-handle You could modify the final response in export const handle = async ({ event, resolve }) => {
// resolve will call the correct load function or endpoint matching the request URL
const response = await resolve(event);
// the response from resolve contains the data, etc. returned from the load or endpoint
// finally, return the response to the client
return response;
} |
Beta Was this translation helpful? Give feedback.
Here is the documentation regarding the
RequestEvent
interface that is available toload
functions in+page.server.js
, endpoints in+server.js
, andhandle
in+hooks.server.js
, etc.https://kit.svelte.dev/docs/types#public-types-requestevent
It will look something like this:
Only the endpoint in
+server.js
andhandle
in+hooks.server.js
can return aResponse
object.https://kit.svelte.dev/docs/hooks#server-hooks-handle
You could modify the final response in
+hooks.server.js
or return a custom response.