there been quite good thread on rest urls in SO.
Is this a bad REST URL? Understanding REST: Verbs, error codes, and authentication
I see a good resource here as well.
The question is how to represent the create and edit forms urls. The So links doesn't clearly say that, but the microformats links suggest
GET /people/new
return a form for creating a new record
GET /people/1/edit
return a form to edit the first record
Not being too religious about using verbs in url, wonder whether there a better option to represent the same.
Although URLs containing parameters within the query string do themselves conform to REST constraints, the term “REST-style URL” is often used to signify a URL that contains its parameters within the URL file path, rather than the query string.
The reason that you will find no consensus on the structure of the URL is because when developers start to understand REST they learn that the structure is irrelevant to the client and is simply a function of aesthetics and server framework implementations.
However, there is a standardized approach to achieving the goals you are trying to achieve.
GET /people/1
Content-Type: application/vnd.hal+xml
=>
<resource rel="self" href="/people/1">
<link rel="edit" href="/people/1/editform"/>
<link rel="urn://vnd.acme.rels/create" href="/people/createform"/>
<name>Joe Foo</name>
</resource>
By embedding links into the response the client can discover the URI needed to perform the desired action. However, to discover the URI, the client needs to have prior knowledge of the link relations ("rel") that are being used. In this case we used "edit" as that has a well defined behaviour described in the IANA Link Registry. The other link for accessing a create form, as far as I know, does not have a standard name, so I took the liberty of creating a uniquely named link relation.
As a side note, I happened to use the media type application/hal+xml because it is a flexible hypermedia format but is simple enough to understand without reading too much documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With