0
0
NextJSframework~5 mins

Response modification in NextJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is response modification in Next.js?
Response modification means changing the server's reply before it reaches the user. In Next.js, you can adjust headers, status codes, or body content in server actions or API routes.
Click to reveal answer
beginner
How do you set a custom header in a Next.js API route?
Use the Response object’s setHeader method. For example, res.setHeader('Cache-Control', 'max-age=3600') adds a cache control header.
Click to reveal answer
beginner
Why would you modify the response status code in Next.js?
Changing the status code helps tell the browser or client what happened. For example, res.status(404) means the page was not found, so the client can handle it properly.
Click to reveal answer
intermediate
What is a common use case for modifying the response body in Next.js server actions?
You might add extra data or format the response before sending it. For example, wrapping data in an object with a message or filtering sensitive info.
Click to reveal answer
intermediate
How does Next.js 14+ support response modification in the App Router?
Next.js 14+ uses server actions and the new Response API, letting you create and return custom Response objects with headers, status, and body directly from route handlers.
Click to reveal answer
In Next.js API routes, which method sets a response header?
Ares.sendHeader()
Bres.getHeader()
Cres.setHeader()
Dres.modifyHeader()
What status code should you use to indicate a resource was not found?
A200
B302
C500
D404
Which Next.js feature allows returning custom Response objects?
AServer Actions
BClient Components
CStatic Props
DgetServerSideProps
Why modify the response body before sending it?
ATo add or format data for the client
BTo change the HTTP method
CTo speed up the server
DTo change the URL
Which of these is NOT a reason to modify response headers?
ASet content type
BChange the request method
CControl caching
DAdd security policies
Explain how you would modify a response in a Next.js API route to add a custom header and set a 200 status code.
Think about how to use res.setHeader and res.status in your handler.
You got /4 concepts.
    Describe the benefits of modifying the response body in Next.js server actions and give an example scenario.
    Consider why you might want to change what the client receives.
    You got /4 concepts.