Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST url for create and edit forms

Tags:

rest

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.

like image 273
bsr Avatar asked Feb 24 '11 12:02

bsr


People also ask

What is REST style URL?

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.


1 Answers

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.

like image 127
Darrel Miller Avatar answered Oct 13 '22 07:10

Darrel Miller