DELETE Method — Removing Resources

Learn how to use the DELETE method to remove resources, handle soft vs hard deletes, and return appropriate status codes.

Unsafe Methods

Detailed Explanation

How DELETE Works

The DELETE method removes the specified resource from the server. After a successful DELETE, subsequent GET requests to the same URI should return 404 Not Found or 410 Gone.

Properties

Property Value
Safe No
Idempotent Yes
Cacheable No
Request Body Optional (rarely used)

Basic DELETE Request

DELETE /api/users/42 HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9...

Response Options

Servers typically respond with one of three status codes:

HTTP/1.1 204 No Content
HTTP/1.1 200 OK
Content-Type: application/json

{ "message": "User 42 deleted successfully" }
HTTP/1.1 202 Accepted
Content-Type: application/json

{ "message": "Deletion queued", "taskId": "abc-123" }
Status When to Use
204 No Content Resource deleted, no body needed
200 OK Resource deleted, response includes details
202 Accepted Deletion is asynchronous / queued

Idempotency of DELETE

DELETE is idempotent: deleting a resource that is already deleted should not produce an error. However, many APIs return 404 on a second DELETE, which is technically acceptable since the end state is the same — the resource no longer exists.

Soft Delete vs Hard Delete

  • Hard delete: Resource is permanently removed from the database
  • Soft delete: A deleted_at timestamp is set; the resource is filtered from queries but can be restored
-- Soft delete
UPDATE users SET deleted_at = NOW() WHERE id = 42;

-- Hard delete
DELETE FROM users WHERE id = 42;

Many production APIs use soft deletes for audit trails and data recovery.

Use Case

A user clicks 'Delete Account' on a settings page, triggering a DELETE request to /api/users/me. An admin dashboard removes a spam post via DELETE /api/posts/1234. A CI pipeline cleans up old deployments by sending DELETE requests to each artifact URL.

Try It — HTTP Method Reference

Open full tool