Update Collection Resource

This example adds an edit form to a tag collection with different mime-types (eg uri-list and application/json-patch+json) for use to update a the resources on a collection. This example updates a tags collection. Navigate to this resource from the home via the ‘me’ > ‘todos’ > pick a todo list > ‘todos’ > pick a todo > ‘tags’.

update todo collection

Goal

  • Update a collection with an edit-form link relation
  • An introduction to uri-list for PUT (make the collection ‘so’)
  • An introduction to application/json-patch+json for PATCH (make collection based on a series of change sets)

Note: both are constrained versions of adding/removing tags (items) from the collection and not updating the tag resources themselves

Note: editing a collection can also be performed by adding items (ie create-form) and/or removing via following the item link and then deleting.

Anatomy of update

Methodlink relassociated routenotes
GET/todo/{id}/tagadd edit-form as a link rel for each of the media types
PUT/todo/{id}/tagsend a text/uri-list
PATCH/todo/{id}/tagsend as a json-patch+json document

Note: by convention a form can be submitted semantically. Here, because the ‘edit-form’ has a type, you submit back onto the originating resource’s ‘self’ link. Note: this design requires the client to know that an ‘edit-form’ type of text/uri-list is a PUT and that an application/json-path+json is a PATCH operation. Furthermore, while each does have an edit form describing their contents, this redundant because these are known media types that the client already knows how to construct.

Important: both are batching strategies that have their place.

Anatomy of code

Return todo (with edit-form links)

Below, you see on overview of the code, then you see the implementation.

Update the resource upon submission

Below, you see on overview of the code, then you see the implementation.

Unlock the next chapter
Updating a collection is going to require responding to which verb(s)?
POST
PUT
PUT & PATCH
POST, PUT & PATCH