0
0
Svelteframework~5 mins

Server routes (+server.js) in Svelte - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of +server.js files in SvelteKit?
They define server-side routes that handle HTTP requests like GET, POST, PUT, and DELETE. These routes run on the server and can fetch or modify data.
Click to reveal answer
beginner
How do you export a GET handler in a +server.js file?
You export an async function named GET that receives a RequestEvent and returns a Response or data wrapped with json().
Click to reveal answer
beginner
What is the difference between client-side routes and server routes in SvelteKit?
Client-side routes handle UI navigation and rendering in the browser. Server routes handle backend logic like data fetching or processing and run on the server.
Click to reveal answer
intermediate
Why should server routes be used for sensitive operations like database access?
Because server routes run on the server, they keep sensitive data and logic hidden from the user, improving security.
Click to reveal answer
beginner
How can you send JSON data from a +server.js route?
Use the json() helper from @sveltejs/kit to return JSON data with proper headers.
Click to reveal answer
What file name does SvelteKit use for server route handlers?
A+server.js
B+page.svelte
Cserver.js
Droute.js
Which HTTP method handler is NOT typically defined in a +server.js file?
AGET
BDELETE
CPOST
DCONNECT
Where does the code in +server.js run?
AOn the server
BIn the browser
CIn the database
DOn the client device
How do you return JSON data from a GET handler in +server.js?
Areturn fetch(data)
Breturn json(data)
Creturn data.toString()
Dreturn new Response(data)
Which import is needed to use the json() helper in +server.js?
Aimport { json } from 'svelte';
Bimport json from 'json';
Cimport { json } from '@sveltejs/kit';
DNo import needed
Explain how to create a simple GET server route in SvelteKit using +server.js.
Think about the function name and how to send JSON back.
You got /4 concepts.
    Describe the difference between client-side routes and server routes in SvelteKit and when to use each.
    Consider where the code runs and what it controls.
    You got /4 concepts.