REST url for create and edit forms
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.
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.
There's an informational RFC recently published that promotes the link relations "create-form" and "edit-form". More information can be located at http://tools.ietf.org/html/rfc6861.
链接地址: http://www.djcxy.com/p/45350.html上一篇: 这是一个糟糕的REST网址吗?
下一篇: 用于创建和编辑表单的REST URL