用于创建和编辑表单的 REST url [英] REST url for create and edit forms

查看:54
本文介绍了用于创建和编辑表单的 REST url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SO 中的 rest url 上有很好的线程.

there been quite good thread on rest urls in SO.

这是一个错误的 REST URL 吗?了解 REST:动词、错误代码和身份验证

我在这里也看到了一个很好的资源.

I see a good resource here as well.

问题是如何表示创建和编辑表单 url.So 链接没有明确说明,但微格式链接建议

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

不要对在 url 中使用动词过于虔诚,想知道是否有更好的选择来表示相同.

Not being too religious about using verbs in url, wonder whether there a better option to represent the same.

推荐答案

你会发现对 URL 的结构没有达成共识的原因是因为当开发人员开始理解 REST 时,他们了解到该结构与客户端无关,并且只是美学和服务器框架实现的功能.

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>

通过在响应中嵌入链接,客户端可以发现执行所需操作所需的 URI.但是,要发现 URI,客户端需要事先了解正在使用的链接关系(rel").在这种情况下,我们使用了编辑",因为它具有在 IANA 链接注册.另一个访问创建表单的链接,据我所知,没有标准名称,所以我冒昧地创建了一个唯一命名的链接关系.

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.

顺便提一下,我碰巧使用了媒体类型 application/hal+xml,因为它是一种灵活的超媒体格式,但足够简单,无需阅读太多文档即可理解.

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.

这篇关于用于创建和编辑表单的 REST url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆