Some web frameworks offer the possibility to “override” the HTTP method with a hidden form field:
<form method="POST">
<input type="hidden" type="_method" value="PUT">
...
</form>
Is it possible to override the HTTP method with the Play framework?
NOTE: This is for Play 1.x only.
Looking at the source code for the
Router.route()method, it uses thex-http-method-overrideparameter in the query string. According to this bug report you should also be able to achieve this using HTTP Headers, but I couldn’t see this in the source code.To get it to work, you need to add the override to the request string. I ran the following example to get it to work.
If you set the logging level to TRACE, you will see the following output, showing the method has changed. You should see an output like —
You can also check the
request.methodin your controller to confirm.