我有一个 REST 数据服务,我希望允许用户使用 HTTP PUT 使用不同的格式(如 json、xml、csv)创建新项目。我不确定如何最好地处理 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 构建查询参数,而不是自己添加它们。
最佳答案
RESTful 网络服务的一般原则是在适用时使用 HTTP 的内置功能。在这种情况下,您可以通过设置 Content-Type 来指示 PUT 请求内容的格式。标题到 application/json 或 application/xml。
关于html - REST 如何在放入资源时处理查询参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49011/