4

我有一个 REST 数据服务,我希望允许用户使用 json、xml、csv 等不同格式的 HTTP PUT 创建新项目。我不确定如何最好地处理 url 中的格式规范:

PUT /ressource/ID/json
PUT /ressource/ID/xml

或者

PUT /ressource/ID?format=json
PUT /ressource/ID?format=xml

那么指定格式指示符的最佳方法是什么?

如果我使用查询参数指定格式并且想要PUT执行此操作,我该如何使用 curl 执行此操作?

curl -T test/data.json -d "format=json"  http://localhost:5000/resource/33

不起作用。

curl -T test/data.json http://localhost:5000/update?format=json

有效,但我宁愿让 curl 构建查询参数,而不是自己添加它们。

4

1 回答 1

15

RESTful Web 服务的一般原则是在适用时使用 HTTP 内置的功能。在这种情况下,您可以通过将Content-Type标头设置为application/jsonapplication/xml来指示 PUT 请求内容的格式。

于 2008-09-08T06:24:48.353 回答