Scala中的RESTful http DELETE方法(播放2.0) [英] RESTful http DELETE method in scala (play 2.0)

查看:134
本文介绍了Scala中的RESTful http DELETE方法(播放2.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Play 2.0构建应用程序.
至于Play表单生成器不会生成本地http删除"请求方法的情况,应将其替换为获取"或发布".

I am building app with Play 2.0.
As far as Play form generator won't generate native http "Delete" request method, it should be replaced with either "Get" or "Post".

@form(routes.Application.delete(id), 'class -> "topRight") {
    <input type="submit" value="Delete this computer" class="btn danger">
}

根据播放示例,发布"应用于删除"目的.尽管使用获取"很方便,因为可以用一个简单的链接替换表单(特别是在单个页面上包含这些链接的列表)

According to Play examples "Post" should be used for "delete" purposes. Though using "Get" is much comfortable as form can be replaced with a simple link (especially having a list of those links on a single page)

那么有什么理由使用POST来模拟DELETE吗?

So is there any reasons to use POST for emulating DELETE?

推荐答案

之所以使用POST代替 GET来模拟DELETE 的原因是因为某些HTTP动词(又名方法)被HTTP规范视为安全. 这些方法是HEADGETOPTIONSTRACE .这意味着使用这些HTTP方法发出请求时,应用程序状态不应有任何副作用.除非是应用程序域的一部分,否则通常不将日志,缓存或计数器的增量视为应用程序状态修改.

The reason to use POST for emulating DELETE instead of GET is because some HTTP verbs (aka methods) are deemed to be safe by the HTTP specification. These methods are HEAD, GET, OPTIONS and TRACE. What this means is there should not be any side effects of application state when making requests using these HTTP methods. Logging, caching, or counter increments are not usually considered application state modification unless it is part of the application domain.

之所以使用POST来模拟DELETE请求而不是直接在Web表单中使用DELETE的原因是,因为许多浏览器不直接支持DELETE.许多使用帮助程序生成表单标记的Web框架(例如Play和Rails)都使用您所引用的技巧将请求映射到代码中相应的REST-ish操作.有关更多信息,请参见浏览器中的HTTP方法支持.另请参见此SO问题有关此主题的更多信息.根据W3C针对HTML5的最新候选推荐, HTML5 元素不支持GET或POST以外的method属性值.对于HTML 4.01中的 FORM元素也是如此. /a>.

The reason to use POST for emulation of DELETE requests instead of directly using DELETE in a web form is because a number of browsers do not support DELETE directly. Many web frameworks that generate form markup with helpers, like Play and Rails, use the trick you refer to to map the request to the corresponding REST-ish action in the code. See HTTP Method Support in Browsers for more information. Please also see this SO question for more information on this topic. According to the W3C latest candidate recommendation for HTML5, the HTML5 FORM element does not support values for the method attribute other than GET or POST. The same is true for the FORM element in HTML 4.01.

这篇关于Scala中的RESTful http DELETE方法(播放2.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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