最好的“造假”方式是什么?使用 JAX-RS 的 DELETE 和 PUT 方法?
我刚刚开始使用 Jersey 为我的网站创建 RESTful API。这是一个奇妙的改变,我必须自己支持 Java 中的 RESTful 服务。我似乎无法弄清楚的一件事是如何“伪造”DELETE 和 PUT 方法。
Jersey 支持注释 @PUT 和 @DELETE,但是许多负载均衡器不允许这些方法通过。过去,我依赖于在 POST 请求中定义自定义 HTTP 标头(例如 x-method-override:DELETE)和“隧道”的能力。
有没有人找到一种方法将使用 Jersey/JAX-RS 注释的方法绑定到自定义标头?或者,是否有更好的方法来解决缺乏对 PUT 和 DELETE 的支持?
I've just started to use Jersey to create a RESTful API for my site. Its a wonderful change from having to roll my own support for RESTful services in Java. One thing I just can't seem to figure out is how to "fake" a DELETE and PUT method.
Jersey supports the annotations @PUT and @DELETE, however many Load-Balancers will not allow these methods through. In the past I've relied on the ability to define a custom HTTP header (e.g. x-method-override: DELETE) and "tunneling" within a POST request.
Has anyone found a way to bind a method using Jersey/JAX-RS annotations to custom headers? Alternatively, is there a better way around lack of support for PUT and DELETE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我决定如何处理 API 中的情况。它相对简单,不需要太多额外的编码。为了说明这一点,请考虑地址的 RESTful api:
}
Well here is how I've decided to handle the situation within my API. Its relatively simple and doesn't require much additional coding. To illustrate consider a RESTful api for Address:
}
它不再是真正的 REST,但在类似的情况下,我们定义 POST /collection/ 进行插入(正常),POST /collection/{id} 进行更新,POST /collection/{id} 不带正文进行删除。
It's not really REST anymore, but in a similar situation we defined POST /collection/ to be insert (as normal), POST /collection/{id} to be update, POST /collection/{id} without body to be delete.