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
