I am trying to design a RESTful service that makes a good use of the Hypermedia.
Preferably, the user agent should only know the root URI in order to be able to explore all the functionality of the service - that is, I would like it to be in the 3rd level in the maturity model.
Now, the user agent should be able to create some resources and also edit them at a later time. At create / edit time, the user agent needs access to some other resource / enumerations.
foo resource:
{
"category" : "category chosen from an enumeration of possible categories",
"color" : "color chosen from an enumeration of possible colors",
"aRelatedResource" : "resource identifier from chosen from a collection"
}
Given the previously mentioned requirements, I have come up with the following pattern:
Have a fooRoot resource:
{
// no properties, only links
"_links" : {
"foos" : { "href" : "URI-to-foos" },
"fooCreator" : { "href" : "URI-to-plain-fooWriter" }
}
}
Include a link to a fooWriter in the foo resource:
foo resource:
{
"category" : "category chosen from an enumeration of possible categories",
"color" : "color chosen from an enumeration of possible colors",
"aRelatedResource" : "resource identifier from chosen from a collection",
"_links" : {
"self" : {...},
"fooEditor" : { "href" : "URI-to-fooWriter-initialized-for-current-foo" }
}
}
A fooWriter would look as follows:
{
"fooPayload" : {
"category" : "NULL or pre-initialized",
"color" : "NULL or pre-initialized",
"aRelatedResource" : "NULL or pre-initialized"
},
"_links" : {
"fooPayloadDestination" : { "href" : "URI-to-foos-or-foo" },
"categoryEnum" : { "href" : "URI-to-categories" },
"colorEnum" : { "href" : "URI-to-colors" },
"availableResourcesToRelateWith" : { "href" : "some-other-URI" },
....
.... and even something useful for pre-validation etc.
"validator" : { href : "URI-to-some-resource-or-service" }
}
}
To sum up, any resource that can be created and edited may have an associated writer resource.
By GET-ting the writer, the user agent can create / edit the resource in a quite convenient manner.
The payload embedded in the writer gets POST-ed to its destination and voilà :)
Also, there should be a root container holding links to both the resource and its writer for new resources (see fooRoot in the example above).
The questions are...
...does the pattern described above have a well-known name?
...is there a better way to solve the create / edit problem, where adjacent resources are required at create / edit time and the 3rd level of maturity still "holds"?
Some references: