Domanda

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.

È stato utile?

Soluzione 2

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") {

}

Altri suggerimenti

Scalatra 2.2.2 (at least) implements HEAD by itself, running the GET code and dropping the information from the body.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top