0
0
NextJSframework~5 mins

Request modification in NextJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is request modification in Next.js?
Request modification means changing the details of an HTTP request before it reaches your server or API route. In Next.js, this can be done using middleware to inspect and alter requests.
Click to reveal answer
intermediate
How do you modify a request URL in Next.js middleware?
You can use the NextResponse.rewrite() method inside middleware to change the request URL, redirecting it to a different path or resource before it reaches the handler.
Click to reveal answer
beginner
Which Next.js feature allows you to run code before a request is completed to modify it?
Middleware in Next.js runs before the request completes and lets you modify the request or response, such as rewriting URLs, adding headers, or redirecting.
Click to reveal answer
intermediate
What is the difference between NextResponse.rewrite() and NextResponse.redirect() in request modification?
NextResponse.rewrite() changes the request URL internally without changing the browser's address bar, while NextResponse.redirect() sends a redirect response that changes the browser's URL.
Click to reveal answer
advanced
Can you modify request headers in Next.js middleware? How?
Yes, you can clone the request and set new headers or modify existing ones inside middleware before passing it on. This helps add authentication tokens or custom data.
Click to reveal answer
Which Next.js feature lets you modify requests before they reach your API or page?
AgetServerSideProps
BMiddleware
CStatic Generation
DClient Components
What does NextResponse.rewrite() do in Next.js middleware?
ARedirects the browser to a new URL
BModifies response headers
CBlocks the request
DChanges the request URL internally without changing the browser URL
How can you add a custom header to a request in Next.js middleware?
AClone the request and set headers on the clone
BUse getStaticProps
CModify the request object directly
DUse client-side JavaScript
Which method sends a response that changes the browser's URL in Next.js middleware?
ANextResponse.redirect()
BNextResponse.json()
CNextResponse.next()
DNextResponse.rewrite()
Where do you place middleware files in a Next.js project?
Acomponents/
Bpages/api/
Cmiddleware.js or middleware.ts (at project root)
Dpublic/
Explain how you can modify an incoming request URL in Next.js using middleware.
Think about how middleware can change the path without redirecting.
You got /4 concepts.
    Describe the difference between rewriting and redirecting a request in Next.js middleware.
    Consider what the user sees in the browser address bar.
    You got /4 concepts.