Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I define multiple HTTP Verbs for an action in Play Framework 2?
    text
    copied!<p>I have an app that requires I define an action for both the HEAD and GET verbs. Another app (Mozilla Open Badges) calls my app using two HTTP requests. It first uses HEAD to verify that my URL looks like it returns the correct type of response, then uses GET against the same URL to fetch the contents. The following approach works:</p> <pre><code>GET /assertion controllers.Assertion.index HEAD /assertion controllers.Assertion.index </code></pre> <p>...this works, but is a DRY violation (Don't Repeat Yourself).</p> <p>I'd prefer something like:</p> <pre><code>(GET, HEAD) /assertion controllers.Assertion.index </code></pre> <p>...but this is not allowed. I would also be happy if GET gave you HEAD for free, but there may be reasons that I don't understand to block HEAD for a GET action.</p> <p>I suppose the redundant Path-to-Action definition isn't the end of the world, but I like to keep my code clean where possible.</p> <p>Based on the W3C spec for HEAD (http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html), I belive Play Framework 2 is behaving incorrecly for not allowing a HEAD call on a route defined for GET:</p> <pre><code>9.4 HEAD The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload