Recall & Review
beginner
What is the purpose of a
route.ts file in Next.js?A
route.ts file defines server-side route handlers that respond to HTTP requests like GET, POST, etc., for a specific API route in Next.js.Click to reveal answer
beginner
How do you export a GET handler in
route.ts?You export an async function named
GET that takes a Request object and returns a Response object.Click to reveal answer
intermediate
Why should route handlers in Next.js be asynchronous?
Because they often perform tasks like fetching data or writing to a database, which are asynchronous operations. Using async lets the server wait for these tasks without blocking.
Click to reveal answer
beginner
What is the difference between a route handler and a React component in Next.js?
A route handler in
route.ts runs on the server to handle HTTP requests, while a React component runs on the client or server to render UI.Click to reveal answer
beginner
How can you send JSON data from a route handler?
Return a
Response with JSON.stringify data and set the Content-Type header to application/json.Click to reveal answer
Which function name is used to handle POST requests in
route.ts?✗ Incorrect
In Next.js route handlers, you export an async function named exactly
POST to handle POST requests.What should a route handler return in Next.js?
✗ Incorrect
Route handlers must return a
Response object that represents the HTTP response.Where do route handler files like
route.ts live in a Next.js project?✗ Incorrect
In Next.js App Router, route handlers live inside the
app directory within the folder for the route.How do you access the request body in a POST route handler?
✗ Incorrect
You use
await request.json() to parse the JSON body from the incoming request.Which HTTP methods can you handle in
route.ts files?✗ Incorrect
You can export async functions named after any HTTP method to handle them in route handlers.
Explain how to create a simple GET route handler in Next.js using
route.ts.Think about how to respond to a GET request with JSON.
You got /4 concepts.
Describe the difference between client-side React components and server-side route handlers in Next.js.
Consider what each part does and where it runs.
You got /4 concepts.