Deployment & Environment Variables in Next.js Quiz – 15 Questions with Answers
15 questions · 12 min · Medium
Test your Next.js knowledge with 20 questions covering API Routes, Route Handlers, Server Actions, HTTP methods, request and response handling, server-side execution, form actions, validation, and secure data mutations.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. route.ts
In the App Router, a route.ts or route.js file is used to define Route Handlers for handling HTTP requests.
A. Inside an app directory route segment
App Router Route Handlers are defined in route.ts or route.js files within the app directory structure.
A. GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS
Route Handlers support standard HTTP methods through named exports such as GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS.
A. NextResponse.json()
NextResponse.json() is a commonly used Next.js API for returning JSON responses from Route Handlers.
A. Request
Route Handlers can receive the standard Web Request object. NextRequest can also be used when Next.js-specific request functionality is needed.
A. To execute server-side functions in response to client interactions
Server Actions allow server-side functions to be invoked from supported client interactions, such as form submissions.
A. use server
The 'use server' directive identifies server-side code that can contain Server Actions.
A. Inside a Server Component or in a dedicated module
Server Actions can be defined in Server Components or exported from a dedicated module using the 'use server' directive.
A. The action attribute
A Server Action can be passed to a form's action prop, allowing the action to run when the form is submitted.
A. A Route Handler exposes an HTTP endpoint, while a Server Action is a server-side function invoked through supported React/Next.js mechanisms
Route Handlers are designed around HTTP requests and responses, while Server Actions provide a mechanism for invoking server-side functions, commonly for mutations.
A. POST
POST is commonly used when a client submits data to create a new resource or perform a server-side operation.
A. await request.json()
The Web Request API provides the asynchronous json() method for reading a JSON request body.
A. FormData
A Server Action used as a form action can receive the submitted fields through the standard FormData object.
A. Server Actions can be invoked through requests and should not trust the caller automatically
Server-side mutations should verify authentication and authorization on the server rather than relying solely on client-side restrictions.
A. They are intended for server-side operations such as data mutations
Server Actions provide a convenient way to perform server-side operations, particularly mutations such as creating, updating, or deleting data.
A. It allows the route to receive a dynamic path parameter
A dynamic segment such as [id] can capture part of the URL and make the value available to the Route Handler.
A. GET
GET is conventionally used to request or retrieve representations of resources without intending to modify server state.
A. revalidatePath()
revalidatePath() can be used in supported server-side contexts to invalidate cached data associated with a specified route path.
A. Sensitive operations should validate authentication, authorization, and input on the server
Server-side code should independently validate incoming data and enforce authentication and authorization for protected operations.
A. Use a Route Handler
Route Handlers are designed to expose HTTP endpoints, making them suitable when clients or systems need to communicate through conventional HTTP requests.