REST PUT 方法的推荐/有效请求负载是什么? [英] What is the recommended/effective request payload for a REST PUT method?

查看:57
本文介绍了REST PUT 方法的推荐/有效请求负载是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在不同的地方看到了两种类型的例子.一种使用像

I see two types of examples in various places. One uses form fields like

curl -X PUT -d "phone=123.456.7890" "http://127.0.0.1/services/rest/user/123"

curl -X PUT -d "phone=123.456.7890" "http://127.0.0.1/services/rest/user/123"

另一个使用 XML 内容,例如(某些变体)这个

and the other uses an XML content like (some variation of) this

echo "123123.456.7890" |curl -X PUT -d @- "http://127.0.0.1/services/rest/user/"

似乎使用表单字段具有简洁的优点,并且通过仅针对修改后的字段来清楚地识别客户的意图,但是却很难处理更深层次"的元数据.

It seems like using the form fields has the advantage of brevity and clearly identifying the client's intent by targeting just the modified fields, but makes it awkward to address "deeper" metadata.

使用 XML 内容的优点是更完整,但缺点是确定客户端实际修改哪个字段的开销(假设他们通过小的修改发回整个资源).

Using the XML content has an advantage of being more complete, but the disadvantage of the overhead of figuring out which field the client is actually modifying (assuming that they send back the entire resource with small modifications).

是否有最佳做法,甚至更常见的做法?

Is there a best practice, or even a more-common practice?

推荐答案

它可能类似于 JSON(P)?(我不确定确切的语法):

It could be something like JSON(P)? (I'm not sure about exact syntax):

$ echo '{user: {id: 123, phone: 123.456.7890}}' |\
> curl -X PUT -d @- 'http://127.0.0.1/services/rest/user/'

$ echo '{phone: 123.456.7890}' |\
> curl -X PUT -d @- 'http://127.0.0.1/services/rest/user/123.json'

这篇关于REST PUT 方法的推荐/有效请求负载是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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