liveBook · Manning

Undelete

As explained in API Design Patterns

An undelete method is an API operation that restores a resource marked as deleted without requiring the resource to be recreated.

Undelete is a custom API operation that restores a soft-deleted resource without recreating it. It reverses the deleted marker while leaving the resource identifier and underlying data intact. section 25.2 section 25.3.3

A resource commonly stores deletion with an output-only deleted Boolean. Standard delete changes false to true; undelete changes it back. If an existing state field represents a lifecycle, a deleted state can be added, but restoration must have a well-defined target state. section 25.3.1 section 25.3.1

Restoring a chat room

Expose an operation such as POST /{id=chatRooms/*}:undelete with an id request and a ChatRoom response. Given a soft-deleted chat room, the operation clears deleted and returns the restored resource. If the chat room is not currently deleted, return an error such as HTTP 412 Precondition Failed rather than silently succeeding. section 25.3.3

Design the operation around these rules:

  • Keep deletion state controlled by delete and undelete; ignore attempts to modify the output-only deleted field through ordinary updates. section 25.3.1
  • Treat undelete as an imperative operation: distinguish a request that caused restoration from a resource that was already restored. section 25.3.3
  • Reset expireTime to null when restoration clears the deleted state; otherwise expiration can permanently remove a resource that has been restored. section 25.3.5
  • Pair undelete with an expunge operation when permanent removal is required, and preserve the referential-integrity rules used by standard deletion. section 25.2 section 25.6
Listing 25.6 Definition of the custom undelete method
abstract class ChatRoomApi {
  @post("/{id=chatRooms/*}:undelete")
  UndeleteChatRoom(req: UndeleteChatRoomRequest):     #1
    ChatRoom;
}
 
interface UndeleteChatRoomRequest {
  id: string;
}

Inspect the concise API definition for the custom method, including its route, request identifier, and returned resource. section 25.3.3

How API Design Patterns covers it

How deep it goes
Defines state transitions, API shape, error semantics, and expiration handling, but stops short of storage implementation internals.
Examples
Uses ChatRoom resources, a POST undelete route, deleted flags, HTTP 412 errors, and expireTime reset behavior.
What it assumes
Assumes familiarity with resource-oriented APIs, standard delete operations, resource fields, and lifecycle states.
What you can do after
Operate/configure an undelete endpoint with explicit restoration state, precondition errors, and expiration cleanup.
How it connects
Connects soft deletion with output-only fields, standard delete methods, expunge methods, state machines, expiration policies, and idempotence.

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.