respondWithStatus

Overrides the status code of all responses coming back from its inner route with the given one.

Signature

def respondWithStatus(responseStatus: StatusCode): Directive0 

Description

This directive transforms HttpResponse and ChunkedResponseStart messages coming back from its inner route by unconditionally overriding the status code with the given one.

Example

val route =
  path("foo") {
    respondWithStatus(201) {
      complete("beep")
    }
  }

Get("/foo") ~> route ~> check {
  status === StatusCodes.Created
  responseAs[String] === "beep"
}