Skip to content
Watch the complete Next.js 15 course on YouTube

DELETE request handlers

This page explains how to implement DELETE request handlers in Next.js for removing resources.

Understanding DELETE requests

DELETE requests remove a specified resource from the server. Unlike PATCH or PUT requests, DELETE requests typically don’t require a request body since the resource identifier is included in the URL.

Creating a DELETE handler

To handle DELETE requests in a dynamic route:

  1. Create a dynamic route handler (see Dynamic route handlers)
  2. Export an async function named DELETE
  3. Process the request and remove the resource
app/api/comments/[id]/route.ts
export async function DELETE(
_request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params;
const index = comments.findIndex((comment) => comment.id === parseInt(id));
const deletedComment = comments[index];
comments.splice(index, 1);
return Response.json(deletedComment);
}

Processing DELETE requests

The handler:

  1. Extracts the resource ID from the route parameters
  2. Finds the resource to delete
  3. Removes the resource from storage
  4. Returns the deleted resource (optional)

Good to know

  • DELETE requests require a dynamic route to identify the resource
  • No request body is needed
  • Changes to in-memory data (like arrays) don’t persist after server restart