代码之家  ›  专栏  ›  技术社区  ›  Srikanth

REST在放入资源时如何处理查询参数?

  •  4
  • Srikanth  · 技术社区  · 16 年前

    我有一个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 -T test/data.json -d "format=json"  http://localhost:5000/resource/33
    

    不起作用。

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

    1 回复  |  直到 9 年前
        1
  •  15
  •   Peter Hilton    16 年前

    RESTfulWeb服务的一般原则是在适用时使用HTTP内置的特性。在这种情况下,您可以通过设置 Content-Type 应用程序/json 应用程序/xml