Skip to content
Mathias edited this page Nov 17, 2011 · 5 revisions

The most basic directives are the method filters. There is one such directive per HTTP method, so in total there are 7 (delete, get, head, options, post, put, trace). They only let requests with the respective HTTP method pass to their inner route and reject all others. Method filter directives do not take parameters and do not extract any values.

Additionally there is also the method directive, which takes an HttpMethod constant as parameter:

import cc.spray.http.HttpMethods._

method(POST) {
  ...
}

If the incoming request has an HTTP method that is different from the one being selected a MethodRejection is being created, which, by default, triggers a 405 Method not allowed error response if no subsequent route successfully handles the request.

Examples

Filter GET requests:

get {
  ... // only GET request will get here
}

Filter PUT or POST requests:

(put | post) {
  ... // only PUT and POST requests will get here
}

Clone this wiki locally