Create Resource

This example constructs a create form for use to create a resource on a collection. This example creates a todo item on a todo list. Navigate to this resource from the home via the ‘me’ > ‘todos’ > pick a todo list > ‘todos’.

create todo resource on todo list collection

Goal

  • Create a collection with a create-form link
  • Create cachable create form (designed to be posted back onto the collection)

Anatomy of search

Methodlink relassociated routenotes
GET/todo/{id}/todo/add create-form as a link rel to collection
GETcreate-form/todo/form/createfollow the tenants link to get the collection
POSTself/todo/{id}/todo/fill in the form and send back to collection. Response returns 201 Created with Location header
GET/todo/{id}follow the Location header returns a filtered search (feed) collection. Note: this is the same route as tenants link rel

Note: by convention a form can be submitted semantically. Here, because there is submit link rel on the form, the forms is send back to the ‘self’ rel on the originating collection resource.

Anatomy of code

Return todo list collection (with create-form link)

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

Create form

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

Create the resource upon submission

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

Unlock the next chapter
How cacheable should a form be?
Always publically cacheable because everyone can always use it
Always private because the form always has the URI of the resource to POST/PUT/PATCH on
Nothing, let the client decide
As much as possible but depends on the payload of the form