这里是单程
> GET http://acme.com/api
< 200 OK
< Content-type: application/hal+xml
<resource>
<!-- Home resource for acme API -->
<link rel="create-form" href="http://acme.com/api/widgets/form{?thingyType,doodaType}"
</resource>
Hal是定义here一个标准的超媒体格式。 create-form
链接关系类型在RFC 6861中定义。 URI使用RFC 6570中定义的URI模板格式。 客户端必须解析URI模板并遵循create-form
的规则检索表单表示。
> GET /acme.com/api/widget?thingyType=foo&doodaType=bar
< 200 OK
< Content-Type: application/xhtml
<html>
<form method="POST"href="http://acme.com/api/widgets">
<input type="text" name="thingyX">
<input type="text" name="thingyY">
<input type="text" name="doodaA">
<input type="text" name="doodaB">
</form>
</html>
在这个例子中,我使用了一个html表单。但是,没有要求使用这种类型的表单。可以使用其他一些表单类型的媒体类型。
> POST http://acme.com/api/widgets
> Content-Type: x-application/www-form-urlencoded
thingyX=20&thingyY=45&doodaA=yo&doodaB=dawg
< 201 Created
< Location: http://acme.com/api/widgets/975
一旦创建了窗口小部件,就可以在您喜欢的任何表示媒体类型中检索窗口小部件。
> GET http://acme.com/api/widgets/975
< 200 OK
< Content-Type: application/vnd.acme.widget+xml
<widget>
<thingy X="20" Y="45">
<dooda A="yo" B="dawg"/>
</widget>
我倾向于将此标记为已接受,因为您按问题回答了问题。然而,当请求和响应只处理Json时,这将如何工作?在我的情况下,客户端只理解Json,并且据我所知,没有Json表单类型。同样,Api期望创建资源的Json对象。 –
@JonnyS有一个hal + json。 Collection + json具有表单机制,尽管它的名字能够处理单个项目。实际上,您可能只需使用collection + json即可完成此操作。 http://amundsen.com/media-types/collection/ –
谢谢,当你回复时,我只是在读这些内容。我会翻阅规范,看看我能否使用它们。 –