使用REST删除http [英] http delete with REST
问题描述
我目前正在使用Jersey框架(JAX-RS实现)来构建RESTful Web服务.项目中的Resource类已实现了标准的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操作,我找不到关于参数类型/格式的任何结论性答案. 删除操作是否在查询字符串(使用@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
应将其删除.
因此,当QueryParam可用于控制工作的某些方面时,我认为使用PathParam比使用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屋!