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?
✗ Incorrect
SvelteKit uses +server.js files to define server-side route handlers.
Which HTTP method handler is NOT typically defined in a +server.js file?
✗ Incorrect
CONNECT is rarely used and not commonly defined in +server.js files; GET, POST, DELETE are standard.
Where does the code in +server.js run?
✗ Incorrect
+server.js code runs on the server, not in the browser or client.
How do you return JSON data from a GET handler in +server.js?
✗ Incorrect
The json() helper formats data with correct headers for JSON responses.
Which import is needed to use the json() helper in +server.js?
✗ Incorrect
You must import json from '@sveltejs/kit' to use it in server routes.
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.