Explicitly rejects the request optionally using the given rejection(s).


def reject: StandardRoute 
def reject(rejections: Rejection*): StandardRoute 


reject uses the given rejection instances (which might be the empty Seq) to construct a Route which simply calls requestContext.reject. See the chapter on Rejections for more information on what this means.

After the request has been rejected at the respective point it will continue to flow through the routing structure in the search for a route that is able to complete it.

The explicit reject directive is used mostly when building Custom Directives, e.g. inside of a flatMap modifier for “filtering out” certain cases.


val route =
  path("a") {
    reject // don't handle here, continue on
  } ~
  path("a") {
  } ~
  path("b") {
    // trigger a ValidationRejection explicitly
    // rather than through the `validate` directive

Get("/a") ~> route ~> check {
  responseAs[String] === "foo"

Get("/b") ~> route ~> check {
  rejection === ValidationRejection("Restricted!")