2

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)

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

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
antiplayer
  • 323
  • 7
  • 15

3 Answers3

10

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.

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.

Community
  • 1
  • 1
Susan Potter
  • 565
  • 2
  • 10
2

For using non - GET or POST methods you should use JavaScript - for an example jQuery $.ajax() and its type setting.

You can also use Play's javascriptRoutes

Community
  • 1
  • 1
biesior
  • 55,576
  • 10
  • 125
  • 182
  • Tnx @biesior. JavascriptRoutes seems to be a good idea, though I am not sure for using js routing right now. Anyway, it was interesting to read about it. Tnx for your link – antiplayer Feb 26 '13 at 10:10
0

Most browsers can't do HTTP requests other than GET or POST from HTML forms, so it's generally emulated using a HTTP POST with an override header or a special form variable.

See Doing a HTTP PUT from a browser

Community
  • 1
  • 1
Xorlev
  • 8,561
  • 3
  • 34
  • 36