liveBook · Manning

Move method

As explained in API Design Patterns

Resource moving is the relocation of an API resource so that it belongs to a different parent or location.

A move method relocates an API resource to a different parent or location, and may also rename its identifier. Use a custom method rather than standard update or create operations because moving can affect child resources, references, metadata, and concurrent users. section 17.0 section 17.6

Design the operation around these rules:

  • Accept the resource identifier and destination identifier; when moving across parents, preserve the existing identifier unless user-selected identifiers are supported. section 17.3.1
  • Move child resources and update references to the relocated resource when the relationship requires it, considering each resource hierarchy case by case. section 17.6
  • Clarify how external data is handled and preserve inherited metadata such as access-control policies. section 17.2
  • Make the operation as atomic as the storage system permits, so failures do not leave partially relocated data. section 17.3.6

Moving a message

Expose a custom endpoint such as POST /{id=chatRooms/*/messages/*}:move with a MoveMessageRequest containing id and destinationId. The method returns the moved Message. A top-level resource without user-specified identifiers generally has no meaningful move operation: it has neither a parent to change nor a valid rename target. section 17.2 section 17.3.1

Listing 17.1 Move-and-copy examples using custom methods
abstract class ChatRoomApi {
  @post("/{id=chatRooms/*/messages/*}:move")         #1
  MoveMessage(req: MoveMessageRequest): Message;     #2
 
  @post("/{id=chatRooms/*}:copy")                    #1    
  CopyChatRoom(req: CopyChatRoomRequest): ChatRoom;  #2
}

Browse the concise API shapes for message moving and chat-room copying. section 17.2

Reconsider the resource layout before adding a move method. Frequent moves can indicate poorly chosen identifiers or a parent-child relationship that should be referential instead. Cutting implementation corners risks lost or corrupted data. section 17.4

How API Design Patterns covers it

How deep it goes
Explains request fields, identifier policy, child resources, references, external data, metadata, and transactional atomicity.
Examples
Uses MoveMessageRequest, chat-room message paths, destination identifiers, and top-level-resource applicability as concrete examples.
What you can do after
Operate/configure a custom move method with explicit identifiers, relationship handling, external-data policy, and feasible atomicity.
How it connects
Connects custom methods with resource identifiers, parent-child relationships, child resources, external data references, and atomicity.

Also explained in

Compare how 2 books explain move method →

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.