liveBook · Manning

Custom expunge method

As explained in API Design Patterns

An expunge method is an API operation that permanently removes a resource and its data, regardless of whether the resource was previously soft-deleted.

A custom expunge method permanently removes a resource after soft deletion, separating irreversible removal from the standard delete method. It should usually accept any resource, whether or not it is already soft-deleted; requiring two requests adds inconvenience without clear benefit. section 25.2 section 25.3.4

Use a separate expunge operation to keep deletion behavior explicit:

  • Keep the standard delete method responsible for marking the resource deleted. section 25.2
  • Use expunge for complete removal rather than overloading one method with a permanent-deletion flag. section 25.3.4
  • Apply the standard delete method’s referential-integrity rules, such as cascading behavior, consistently where required. section 25.6
Listing 25.7 Definition of the custom expunge method
abstract class ChatRoomApi {
  @post("/{id=chatRooms/*}:expunge")
  ExpungeChatRoom(req: ExpungeChatRoomRequest): void;   #1
}
 
interface ExpungeChatRoomRequest {
  id: string;
}

A ChatRoom API exposes expunging as an explicit POST action on the resource. section 25.3.4

How API Design Patterns covers it

How deep it goes
Defines the operation, compares method designs, and addresses whether prior soft deletion should be required.
Examples
Uses a ChatRoom POST action and exercises about expunging resources that are not already soft-deleted.
What it assumes
Assumes familiarity with resource APIs and teaches the relationship between soft deletion, restoration, and permanent removal.
What you can do after
Operate/configure an API with an explicit permanent-removal action that avoids an unnecessary soft-delete prerequisite.
How it connects
Connects soft deletion with standard delete methods, custom undelete methods, and referential integrity.

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.