Search code examples
scalarestscalatra

HEAD request in scalatra


I am a scalatra newbie, and maybe my question makes no sense, but here it is:

How do I tell if a request in scalatra was a GET or a HEAD request?

Basically I have a REST api which uses GET to get an item, and HEAD to test that the item exists. I am not seeing an obvious way of writing a handler for a HEAD request.


Solution

  • This seems to work. I am not sure if it's the right way, and it's not clean (scalatra should make HEAD a first class citizen). Anyway, hopefully someone will correct me if I'm doing something wrong. but this is my newbie attempt... Not exactly sure if case matters.

    get ("/something",request.getMethod == "HEAD") {
    
    }
    
    get ("/something",request.getMethod == "GET") {
    
    }