liveBook · Manning

Deletion

As explained in API Design Patterns

A delete method is an API operation that removes an existing resource.

A delete method removes an existing resource. A standard operation targets the resource by unique identifier, uses HTTP DELETE, and normally returns an empty value after successful removal. section 7.2 section 7.3.7

Define the behavior explicitly before implementing the method:

  • Decide whether deleting a missing resource reports the current result—already absent—or the action’s failure, such as 404 Not Found. section 7.2
  • Choose whether repeated deletion is declarative and idempotent, or imperative and able to fail when the resource is already absent. section 7.3.7
  • Distinguish authorization failures from nonexistence deliberately; returning 403 Forbidden or 404 Not Found affects information disclosure. section 7.2
  • Support delete only where the resource model permits it; permanent or immutable resources can expose the method but reject attempts with 403 Forbidden. section 7.3.1

Deleting a chat room

A resource-oriented API can expose DeleteChatRoom with an identifier such as chatRooms/{id}. A successful hard delete makes the ChatRoom disappear and returns no resource payload. section 7.3.7

Listing 7.5 The standard delete method
abstract class ChatRoomApi {
  @delete("/{id=chatRooms/*}")                       #1
  DeleteChatRoom(req: DeleteChatRoomRequest): void;  #2
}
 
interface DeleteChatRoomRequest {
  id: string;
}

Inspect the compact method definition showing the HTTP DELETE path, identifier request, and void result. section 7.3.7

Soft deletion changes the operation from physical removal to marking the resource deleted. The method returns the modified resource, ordinary listing hides it, undelete restores it, and permanent removal requires a separate custom method. section 25.3 section 25.3.2

How API Design Patterns covers it

How deep it goes
Defines request shape and return behavior, then works through idempotence, status ambiguity, permissions, and soft-deletion changes.
Examples
Uses DeleteChatRoom, chatRooms/{id}, repeated deletion, immutable resources, and soft-deleted ChatRoom listing scenarios.
What it assumes
Assumes familiarity with API resources, unique identifiers, HTTP methods, and HTTP response codes.
What you can do after
Operate/configure a delete endpoint with explicit absence, authorization, repetition, and soft-deletion policies.
How it connects
Connects HTTP DELETE, idempotence, authorization, HTTP status codes, list methods, update methods, soft deletion, undelete, and permanent removal.

Also explained in

Compare how 8 books explain deletion →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.