Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
A route handler receives and processes requests made to a particular URL path.
Question 2 of 60 · REST APIs · Easy
What does REST commonly describe in web development?
Not quite. Try another option.
Answer: A style for designing web APIs
REST is an architectural style used to design APIs around resources and standard HTTP operations.
Question 3 of 60 · HTTP Methods · Easy
Which HTTP method is commonly used to retrieve data?
Not quite. Try another option.
Answer: GET
The GET method is used to request or retrieve data from a server.
Question 4 of 60 · HTTP Methods · Easy
Which HTTP method is commonly used to create new data?
Not quite. Try another option.
Answer: POST
The POST method is commonly used to send data to a server to create a new resource.
Question 5 of 60 · Dynamic Route Handlers · Easy
What does a dynamic route usually contain?
Not quite. Try another option.
Answer: A variable path segment
A dynamic route contains a variable segment, such as an identifier for a specific product or user.
Question 6 of 60 · Dynamic Route Handlers · Easy
In a route such as /users/42, what might 42 represent?
Not quite. Try another option.
Answer: A user identifier
A dynamic route segment such as 42 often identifies a particular resource.
Question 7 of 60 · Request and Response Handling · Easy
What does a server receive from a client in a web request?
Not quite. Try another option.
Answer: Request data
A request can contain information such as the URL, method, headers, query parameters, and body.
Question 8 of 60 · Request and Response Handling · Easy
What does a server send back after processing a request?
Not quite. Try another option.
Answer: A response
The server returns a response that can include a status code, headers, and data.
Question 9 of 60 · Request and Response Handling · Easy
Which status code usually means that a request succeeded?
Not quite. Try another option.
Answer: 200
The HTTP status code 200 indicates that the request was successfully processed.
Question 10 of 60 · Server Actions · Easy
What is a server action designed to do?
Not quite. Try another option.
Answer: Run specific logic on the server
A server action allows application logic, such as a mutation, to execute on the server.
Question 11 of 60 · Server Actions · Easy
Which task is a suitable use for a server action?
Not quite. Try another option.
Answer: Saving submitted form data
Server actions are useful for server-side tasks such as creating or updating records.
Question 12 of 60 · Form Handling · Easy
What is the purpose of a form in a web application?
Not quite. Try another option.
Answer: To collect user input
Forms provide controls that allow users to enter and submit information.
Question 13 of 60 · Form Handling · Easy
Which event commonly occurs when a user sends a form?
Not quite. Try another option.
Answer: Submit
The submit event occurs when a form is sent for processing.
Question 14 of 60 · Form Validation · Easy
What is the main purpose of form validation?
Not quite. Try another option.
Answer: To check whether input is acceptable
Validation checks that submitted values meet required rules, such as format or length.
Question 15 of 60 · Form Validation · Easy
Which input would usually fail validation for an email field?
Not quite. Try another option.
Answer: alex.example.com
An email value normally includes an @ symbol separating the user and domain parts.
Question 16 of 60 · File Upload · Easy
Which HTML control is commonly used to select a file?
Not quite. Try another option.
Answer: An input with type file
An <input type="file"> control allows users to choose a file from their device.
Question 17 of 60 · File Upload · Easy
Which object commonly represents an uploaded file in web APIs?
Not quite. Try another option.
Answer: File
The File object contains information about a selected file, such as its name, type, and size.
Question 18 of 60 · Data Mutations · Easy
What is a data mutation?
Not quite. Try another option.
Answer: An operation that changes stored data
Mutations include actions such as creating, updating, or deleting database records.
Question 19 of 60 · Optimistic UI Updates · Easy
What is an optimistic UI update?
Not quite. Try another option.
Answer: Updating the interface before server confirmation
An optimistic update immediately shows the expected result while the server request is still completing.
Question 20 of 60 · Optimistic UI Updates · Easy
What should an application do if an optimistic update fails on the server?
Not quite. Try another option.
Answer: Revert or correct the displayed state
If the server rejects the change, the interface should be synchronized with the actual server state.
Question 21 of 60 · Route Handlers · Medium
A route handler receives a POST /api/orders request containing JSON. Which sequence is most appropriate for creating the order?
Not quite. Try another option.
Answer: Parse the body, validate it, save the order, and return a status
A POST handler should parse and validate input before performing the mutation, then return an appropriate response such as 201 Created.
Question 22 of 60 · Route Handlers · Medium
A route handler must return a JSON object containing { "status": "ok" }. Which response is most suitable?
Not quite. Try another option.
Answer: A JSON response with a 200 status
When the request succeeds and the result is JSON, the handler should return JSON with a successful status such as 200 OK.
Question 23 of 60 · REST APIs · Medium
Which endpoint design best follows REST conventions for retrieving one product with ID 42?
Not quite. Try another option.
Answer: GET /api/products/42
REST APIs generally represent resources with nouns and use the path to identify a specific resource.
Question 24 of 60 · REST APIs · Medium
A client requests a collection of published articles with pagination. Which design is most appropriate?
Not quite. Try another option.
Answer: GET /api/articles?status=published&page=2
Collection filtering and pagination are commonly expressed with query parameters on a GET request.
Question 25 of 60 · HTTP Methods · Medium
A user changes the title of an existing article and sends the complete updated article representation. Which HTTP method is the best fit?
Not quite. Try another option.
Answer: PUT
PUT is commonly used to replace an existing resource with a complete representation, while PATCH usually represents a partial update.
Question 26 of 60 · HTTP Methods · Medium
Which status code best indicates that a new account was successfully created by a POST request?
Not quite. Try another option.
Answer: 201 Created
201 Created specifically communicates that the request successfully created a new resource.
Question 27 of 60 · Dynamic Route Handlers · Medium
A dynamic route is defined as /api/users/[id]. A request arrives at /api/users/73. What should the handler use to identify the requested user?
Not quite. Try another option.
Answer: The route parameter id with value 73
The [id] segment captures the corresponding path value, so the handler receives id as 73.
Question 28 of 60 · Dynamic Route Handlers · Medium
A request to /api/posts/abc cannot find a post with ID abc. What should the dynamic route handler normally return?
Not quite. Try another option.
Answer: A 404 Not Found response
A dynamic route can match syntactically while the resource is absent. In that case, 404 Not Found is the appropriate response.
Question 29 of 60 · Request and Response Handling · Medium
A client sends invalid JSON to an endpoint that expects a JSON body. How should the handler respond?
Not quite. Try another option.
Answer: Return a 400 Bad Request response
Malformed JSON means the client request cannot be processed as sent, so a 400 Bad Request response is appropriate.
Question 30 of 60 · Request and Response Handling · Medium
An API endpoint returns a list of users but must prevent browsers and intermediaries from reusing stale data. Which response behavior is most relevant?
Not quite. Try another option.
Answer: Set appropriate cache-control headers
Cache behavior is controlled through response headers such as Cache-Control, which can prevent or limit reuse of stale responses.
Question 31 of 60 · Server Actions · Medium
A form invokes a server action that inserts a record into a database. Which security practice is still required?
Not quite. Try another option.
Answer: Validate authorization inside the server action
Server actions run on the server but still receive potentially manipulated input. Authentication and authorization must be checked server-side.
Question 32 of 60 · Server Actions · Medium
After a server action updates a product name, the page still displays the old cached product data. What is the most appropriate follow-up?
Not quite. Try another option.
Answer: Revalidate or refresh the affected data
Mutations can leave cached data stale. Revalidating the relevant path or data query ensures that subsequent rendering uses the updated value.
Question 33 of 60 · Form Handling · Medium
A form submits a username and a profile image to a server action. Which encoding is needed to transmit both fields correctly?
Not quite. Try another option.
Answer: multipart/form-data
multipart/form-data supports both ordinary form fields and binary file parts in the same submission.
Question 34 of 60 · Form Handling · Medium
A form should show a pending indicator while its server action is running and then disable the submit button. What is the best approach?
Not quite. Try another option.
Answer: Track the action's pending state in the UI
Using the action's pending state lets the interface provide immediate feedback and prevents duplicate submissions during the request.
Question 35 of 60 · Form Validation · Medium
A registration form checks that an email is present in the browser. Why must the server repeat this validation?
Not quite. Try another option.
Answer: Client-side checks can be bypassed
Users or malicious clients can submit requests without using the browser interface, so the server must enforce all important validation rules.
Question 36 of 60 · Form Validation · Medium
A form requires a product quantity to be an integer from 1 through 10. Which server-side rule correctly enforces this requirement?
Not quite. Try another option.
Answer: Check that the parsed value is an integer and lies between 1 and 10
Validation must check both the data type and the allowed range; checking only presence or digits is insufficient.
Question 37 of 60 · File Upload · Medium
An upload endpoint accepts profile images. Which validation combination provides the strongest basic protection?
Not quite. Try another option.
Answer: Check size, MIME type, extension, and generated storage name
Uploads should be constrained by size and type, while generated names reduce collisions and risks from user-controlled filenames.
Question 38 of 60 · File Upload · Medium
A user uploads a file named ../../avatar.png. What is the safest storage behavior?
Not quite. Try another option.
Answer: Ignore the supplied path and generate a safe filename
User-controlled paths can enable path traversal. The server should generate a safe name and control the storage location.
Question 39 of 60 · Data Mutations · Medium
A delete operation is requested for an invoice that does not exist. Which behavior is generally most useful for an idempotent API?
Not quite. Try another option.
Answer: Return success or a consistent not-found result by API design
Repeating a DELETE should not cause additional changes. APIs commonly choose either a successful no-op or a consistent 404 response.
Question 40 of 60 · Data Mutations · Medium
Two users edit the same document. Which technique best helps prevent one update from silently overwriting a newer update?
Not quite. Try another option.
Answer: Use version checks or optimistic concurrency control
Comparing a submitted version with the current version allows the server to detect stale updates and reject or resolve conflicts.
Question 41 of 60 · Route Handlers · Hard
A Next.js App Router project contains app/reports/page.tsx. A developer adds app/reports/route.ts to expose a JSON endpoint at /reports, and the build reports a route conflict. Which change correctly resolves the conflict while preserving both interfaces?
Not quite. Try another option.
Answer: Move the handler to app/reports/api/route.ts and expose it at /reports/api
A route.ts handler cannot coexist with page.tsx at the same route segment. Placing the handler in a child segment gives it a distinct URL.
Question 42 of 60 · REST APIs · Hard
An API paginates orders sorted by createdAt DESC. New orders may share timestamps and may be inserted while clients paginate. Which cursor design most reliably prevents skipped or duplicated records?
Not quite. Try another option.
Answer: Use an opaque cursor containing both createdAt and the unique order ID
A stable cursor needs the complete sort key. Adding a unique ID as a tie-breaker gives deterministic ordering when timestamps are equal.
Question 43 of 60 · HTTP Methods · Hard
A client times out after sending a payment-creation request and cannot determine whether the server committed it. Which API design best permits a safe retry without creating a second payment?
Not quite. Try another option.
Answer: Send POST with an idempotency key stored under a unique constraint
The server can atomically associate the key with one result and return that result for retries. POST is not inherently idempotent, so the key must be enforced server-side.
Question 44 of 60 · Dynamic Route Handlers · Hard
A handler is defined at app/api/docs/[[...slug]]/route.ts. Assuming the route parameters have been resolved, what values should it expect for requests to /api/docs and /api/docs/guides/install?
Not quite. Try another option.
Answer: slug is undefined first and ["guides", "install"] second
An optional catch-all parameter is absent at the segment root and becomes an array containing each matched child segment for deeper URLs.
Question 45 of 60 · Request and Response Handling · Hard
A Route Handler must verify an HMAC over the exact raw request body and then parse the same body as JSON. Which approach is valid with the Fetch Request API?
Not quite. Try another option.
Answer: Clone the request before consumption, then read one body as text and the other as JSON
A request body is a one-use stream. A clone creates another readable stream, while reserializing JSON may change whitespace, key order, or byte representation.
Question 46 of 60 · Request and Response Handling · Hard
A Route Handler must set two cookies with different attributes in one response. Which implementation preserves both cookies correctly?
Not quite. Try another option.
Answer: Use NextResponse.cookies.set once for each cookie before returning
NextResponse.cookies.set emits the required cookie headers correctly. Overwriting or comma-joining Set-Cookie values can lose cookies or corrupt attributes.
Question 47 of 60 · Server Actions · Hard
A Server Action called by an authenticated page receives accountId from submitted form data and deletes that account. What security check is essential inside the action?
Not quite. Try another option.
Answer: Authorize the current server-side identity for the submitted accountId
Server Actions are security boundaries. Submitted and bound values are untrusted, so the action must authenticate the caller and authorize access to the specific resource.
Question 48 of 60 · Form Handling · Hard
A Server Action has the signature updateUser(userId, formData). Which expression correctly supplies userId while allowing <form action={...}> to provide the submitted FormData?
Binding supplies the leading argument. React then appends the submitted FormData, producing the call updateUser(userId, formData).
Question 49 of 60 · Form Validation · Hard
A registration form performs schema validation in the browser. The associated Server Action writes directly to the database without validating again. Which revision provides the correct trust boundary and supports field-level errors?
Not quite. Try another option.
Answer: Parse FormData with the schema in the action and return structured field errors
Client validation improves usability but can be bypassed. The server must validate untrusted input and can return a structured state that maps errors to form fields.
Question 50 of 60 · File Upload · Hard
A Route Handler accepts multi-gigabyte uploads, but await request.formData() followed by await file.arrayBuffer() exhausts memory. Which architecture best addresses the problem?
Not quite. Try another option.
Answer: Stream bytes to storage while enforcing incremental size and type limits
Streaming avoids holding the entire upload in memory. Limits must be enforced while reading because metadata such as Content-Length may be absent or unreliable.
Question 51 of 60 · Data Mutations · Hard
An endpoint transfers credits by decrementing one balance, incrementing another, and inserting a ledger entry. Which implementation preserves consistency when a database operation fails halfway through?
Not quite. Try another option.
Answer: Execute all three writes in one database transaction
A transaction commits all related writes atomically or rolls them all back. Concurrent promises do not provide rollback or atomicity.
Question 52 of 60 · Optimistic UI Updates · Hard
A user renames the same item twice before the first mutation finishes. The first request fails after the second optimistic rename has been displayed. What rollback strategy avoids overwriting the newer state?
Not quite. Try another option.
Answer: Rollback only if the current optimistic version matches the failed operation
Each optimistic operation should carry an identity or version. A stale failure must not restore an older snapshot over a newer user action.
Question 53 of 60 · Route Handlers · Hard
A browser sends a cross-origin PUT request with Content-Type: application/json and an Authorization header. The API's PUT handler is correct, but the browser never sends the actual request. What is the most likely missing behavior?
Not quite. Try another option.
Answer: An OPTIONS handler returning the required CORS allow headers
This non-simple request triggers a CORS preflight. The server must answer OPTIONS with allowed origins, methods, and headers, and include the appropriate origin header on the actual response.
Question 54 of 60 · REST APIs · Hard
A POST /exports request starts a long-running export and returns before processing is complete. Which response most accurately represents the REST semantics?
Not quite. Try another option.
Answer: 202 Accepted with a location for checking job status
202 Accepted indicates that processing has been accepted but is not complete. A status resource lets the client observe eventual completion or failure.
Question 55 of 60 · HTTP Methods · Hard
Two administrators retrieve version 7 of a document. One updates it to version 8; the other then submits changes based on version 7. Which HTTP mechanism best prevents the second update from silently overwriting the first?
Not quite. Try another option.
Answer: Require If-Match with the version 7 ETag and return 412 on mismatch
If-Match makes the mutation conditional on the resource still having the client's ETag. A changed ETag causes 412 Precondition Failed.
Question 56 of 60 · Dynamic Route Handlers · Hard
A multi-tenant handler uses /api/tenants/[tenantId]/invoices/[invoiceId]. The session proves the user belongs to tenant A, but the URL specifies tenant B. What should the handler do before retrieving the invoice?
Not quite. Try another option.
Answer: Reject access unless the identity is authorized for URL tenant B
Dynamic route parameters are untrusted input. Authorization must bind the authenticated identity to the tenant and resource named by the request.
Question 57 of 60 · Request and Response Handling · Hard
A successful DELETE operation has no representation to return. Which response is valid according to HTTP semantics?
Not quite. Try another option.
Answer: Return status 204 with no response body
204 No Content indicates success and cannot include a message body. Use 200 if a confirmation representation needs to be returned.
Question 58 of 60 · Server Actions · Hard
A Server Action wraps its mutation and redirect("/dashboard") inside a broad try...catch. Successful submissions unexpectedly return the generic error state instead of navigating. What is the correct fix?
Not quite. Try another option.
Answer: Call redirect after the try...catch once the mutation succeeds
In Next.js, redirect works by throwing a framework-handled control-flow exception. A broad catch can intercept it, so redirect after the mutation's error-handling block.
Question 59 of 60 · Optimistic UI Updates · Hard
A client optimistically inserts comments using temporary IDs. The server returns the persisted comment with a canonical ID and normalized text. What is the correct reconciliation behavior?
Not quite. Try another option.
Answer: Replace the matching temporary entry with the returned canonical comment
The client should correlate the response with the optimistic operation and replace that entry. This avoids duplicates and adopts server-generated fields and normalization.
Question 60 of 60 · File Upload · Hard
An upload endpoint stores files using the client-provided File.name under a public directory. Which design best mitigates path traversal, collisions, and misleading file-type metadata?
Not quite. Try another option.
Answer: Generate a server-side storage key and validate content independently of the filename
Client filenames and MIME declarations are untrusted. A generated key avoids traversal and collision risks, while content-aware validation verifies the actual uploaded data.
That's unit 3
Answer a few questions and your score shows up here.
Nearly through. Did unit 3 of INT257 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 3 of INT257 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.