liveBook · Manning

Custom create revision method

As explained in API Design Patterns

A custom create revision method is an API operation that captures the current state of a resource as a new revision.

A custom create revision method explicitly snapshots a resource at a chosen moment and creates a new revision. It moves revision policy from the API to the user, avoiding unnecessary implicit revisions. section 28.3.2

Design the operation with these rules:

  • Give the method one responsibility: capture the resource’s current state as a revision. section 28.3.2
  • Generate the revision identifier randomly and set its creation timestamp when persistence completes. section 28.3.2
  • Use explicit creation when users, rather than updates, should determine the revision policy. section 28.3.2

Message revision endpoint

Expose POST /{id=chatRooms/*/messages/*}:createRevision. Accept the message identifier, snapshot the current message, and return a Message containing revisionId and revisionCreateTime. section 28.3.2

Listing 28.3 API definition for creating a resource revision
abstract class ChatRoomApi {
  @post("/{id=chatRooms/*/messages/*}:createRevision")
  CreateMessageRevision(req: CreateMessageRevisionRequest):   #1    
    Message;
}
 
interface Message {
  id: string;
  content: string;
  // ...
  revisionId: string;                                         #2
  revisionCreateTime: Date;                                   #2
}
 
interface CreateMessageRevisionRequest {
  id: string;                                                 #3
}

Inspect the compact API definition for the custom method, request identifier, and revision metadata. section 28.3.2

How API Design Patterns covers it

How deep it goes
Defines responsibility, identifier generation, and persistence timing, but does not detail revision retrieval.
Examples
Uses a ChatRoom message endpoint with a createRevision method, message identifier, revisionId, and revisionCreateTime.
What it assumes
Assumes familiarity with resources and standard create methods while defining revision snapshots and explicit policy.
What you can do after
Build it from scratch as an explicit API operation that snapshots a resource and returns revision metadata.
How it connects
Connects custom methods with resource revisions, snapshots, standard create methods, and resource updates.

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.