使用 REST 删除 http [英] http delete with REST

查看:22
本文介绍了使用 REST 删除 http的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Jersey 框架(JAX-RS 实现)来构建 RESTful Web 服务.项目中的资源类已经实现了标准的 HTTP 操作——GET,POST &删除.我试图弄清楚如何将请求参数从客户端发送到这些方法.

I am currently using Jersey Framework (JAX-RS implementation) for building RESTful Web Services. The Resource classes in the project have implemented the standard HTTP operations - GET,POST & DELETE. I am trying to figure out how to send request parameters from client to these methods.

对于 GET 它将在查询字符串中(使用 @QueryParam 提取),POST 将是名称/值对列表(使用 @FormParam 提取)发送请求正文.我使用 HTTPClient 对它们进行了测试并且工作正常.对于 DELETE 操作,我没有找到关于参数类型/格式的任何结论性答案.DELETE 操作是否接收查询字符串中的参数(使用 @QueryParam 提取)或正文中(使用 @FormParam 提取)?

For GET it would be in the query string(extract using @QueryParam) and POST would be name/value pair list (extract using @FormParam) sent in with the request body. I tested them using HTTPClient and worked fine. For DELETE operation, I am not finding any conclusive answers on the parameter type/format. Does DELETE operation receive parameters in the query string(extract using @QueryParam) or in the body(extract using @FormParam)?

在网络上的大多数 DELETE 示例中,我观察到使用 @PathParam 注释进行参数提取(这将再次来自查询字符串).

In most DELETE examples on the web, I observe the use of @PathParam annotation for parameter extraction(this would be from the query string again).

这是将参数传递给 DELETE 方法的正确方法吗?我只是想在这里小心一点,以免违反任何 REST 原则.

Is this the correct way of passing parameters to the DELETE method? I just want to be careful here so that I am not violating any REST principles.

推荐答案

是的,这取决于你,但是当我了解 REST 思想时,DELETE URL 应该删除 GET URL 请求返​​回的内容.例如,如果

Yes, its up to you, but as I get REST ideology, DELETE URL should delete something that is returned by a GET URL request. For example, if

GET http://server/app/item/45678

返回 id 为 45678 的项目,

returns item with id 45678,

DELETE http://server/app/item/45678

应该删除它.

因此,我认为使用 PathParam 比使用 QueryParam 更好,因为 QueryParam 可以用于控制工作的某些方面.

Thus, I think it is better to use PathParam than QueryParam, when QueryParam can be used to control some aspects of work.

DELETE http://server/app/item/45678?wipeData=true

这篇关于使用 REST 删除 http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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