Predefined Directives (alphabetically)

DirectiveDescription
@refalwaysCacheWraps its inner Route with caching support using the given @apidoc[Cache] implementation and the in-scope keyer function.
@refattributeExtracts the value of the request attribute with a given key
@refauthenticateBasicWraps the inner route with Http Basic authentication support using a given @scala[Authenticator[T]]@java[Authenticator<T>]
@refauthenticateBasicAsyncWraps the inner route with Http Basic authentication support using a given @scala[AsyncAuthenticator[T]]@java[AsyncAuthenticator<T>]
@refauthenticateBasicPFWraps the inner route with Http Basic authentication support using a given @scala[AuthenticatorPF[T]]@java[AuthenticatorPF<T>]
@refauthenticateBasicPFAsyncWraps the inner route with Http Basic authentication support using a given @scala[AsyncAuthenticatorPF[T]]@java[AsyncAuthenticatorPF<T>]
@refauthenticateOAuth2Wraps the inner route with OAuth Bearer Token authentication support using a given @scala[AuthenticatorPF[T]]@java[AuthenticatorPF<T>]
@refauthenticateOAuth2AsyncWraps the inner route with OAuth Bearer Token authentication support using a given @scala[AsyncAuthenticator[T]]@java[AsyncAuthenticator<T>]
@refauthenticateOAuth2PFWraps the inner route with OAuth Bearer Token authentication support using a given @scala[AuthenticatorPF[T]]@java[AuthenticatorPF<T>]
@refauthenticateOAuth2PFAsyncWraps the inner route with OAuth Bearer Token authentication support using a given @scala[AsyncAuthenticatorPF[T]]@java[AsyncAuthenticatorPF<T>]
@refauthenticateOrRejectWithChallengeLifts an authenticator function into a directive
@refauthorizeApplies the given authorization check to the request
@refauthorizeAsyncApplies the given asynchronous authorization check to the request
@refcacheWraps its inner Route with caching support using the given @apidoc[Cache] implementation and the in-scope keyer function.
@refcachingProhibitedPasses only requests that explicitly forbid caching with a Cache-Control header with either a no-cache or max-age=0 setting.
@refcancelRejectionAdds a @apidoc[TransformationRejection] cancelling all rejections equal to the given one to the rejections potentially coming back from the inner route.
@refcancelRejectionsAdds a @apidoc[TransformationRejection] cancelling all matching rejections to the rejections potentially coming back from the inner route
@refcheckSameOriginChecks that the request comes from the same origin
@refcompleteCompletes the request using the given arguments
@refcompleteOrRecoverWith“Unwraps” a @scala[Future[T]]@java[CompletionStage<T>] and runs the inner route when the future has failed with the error as an extraction of type Throwable
@refcompleteWithUses the marshaller for a given type to extract a completion function
@refconditionalWraps its inner route with support for conditional requests as defined by RFC 7232
@refcookieExtracts the @apidoc[HttpCookie] with the given name
@refdecodeRequestDecompresses the request if it is gzip or deflate compressed
@refdecodeRequestWithDecodes the incoming request using one of the given decoders
@refdeleteRejects all non-DELETE requests
@refdeleteCookieAdds a Set-Cookie response header expiring the given cookies
@refencodeResponseEncodes the response with the encoding that is requested by the client via the Accept-Encoding header (NoCoding, Gzip and Deflate)
@refencodeResponseWithEncodes the response with the encoding that is requested by the client via the Accept-Encoding header (from a user-defined set)
@refentityExtracts the request entity unmarshalled to a given type
@refextractExtracts a single value using a @scala[RequestContext => T]@java[Function<RequestContext, T>] function
@scala[@refextractDataBytes]@scala[Extracts the entities data bytes as a stream @apidoc[Source[ByteString, _]]]
@refextractClientIPExtracts the client's IP from either the X-Forwarded- or X-Real-IP header
@refextractCredentialsExtracts the potentially present @apidoc[HttpCredentials] provided with the request's @apidoc[Authorization] header
@refextractExecutionContextExtracts the ExecutionContext from the @apidoc[RequestContext]
@refextractMatchedPathExtracts the already matched path from the @apidoc[RequestContext]
@refextractMaterializerExtracts the @apidoc[Materializer] from the @apidoc[RequestContext]
@refextractHostExtracts the hostname part of the Host request header value
@refextractLogExtracts the @apidoc[LoggingAdapter] from the @apidoc[RequestContext]
@refextractMethodExtracts the request method
@refextractOfferedWsProtocolsExtract the list of websocket subprotocols offered by the client in the Sec-WebSocket-Protocol header if this is a websocket request and otherwise rejects with an @apidoc[ExpectedWebSocketRequestRejection$]
@refextractParserSettingsExtracts the @apidoc[ParserSettings] from the @apidoc[RequestContext]
@refextractRequestExtracts the current @apidoc[HttpRequest] instance
@refextractRequestContextExtracts the @apidoc[RequestContext] itself
@scala[@refextractRequestEntity]@scala[Extracts the @apidoc[RequestEntity] from the @apidoc[RequestContext]]
@refextractSchemeExtracts the URI scheme from the request
@refextractSettingsExtracts the @apidoc[RoutingSettings] from the @apidoc[RequestContext]
@refextractUnmatchedPathExtracts the yet unmatched path from the @apidoc[RequestContext]
@refextractUriExtracts the complete request URI
@reffailWithBubbles the given error up the response chain where it is dealt with by the closest @refhandleExceptions directive and its @apidoc[ExceptionHandler]
@reffileUploadProvides a stream of an uploaded file from a multipart request
@reffileUploadAllProvides streams of all uploaded files from a multipart request
@refformFieldExtracts an HTTP form field (of Content-Type application/x-www-form-urlencoded or multipart/form-data) from the request
@refformFieldMapExtracts a number of HTTP form field (of Content-Type application/x-www-form-urlencoded or multipart/form-data) from the request as a @scala[Map[String, String]]@java[Map<String, String>]
@refformFieldMultiMapExtracts a number of HTTP form field (of Content-Type application/x-www-form-urlencoded or multipart/form-data) from the request as a @scala[Map[String, List[String]]]@java[Map<String, List<String>>]
@scala[@refformFields]@scala[Extracts a number of HTTP form field (of Content-Type application/x-www-form-urlencoded or multipart/form-data) from the request]
@refformFieldSeqExtracts a number of HTTP form field (of Content-Type application/x-www-form-urlencoded or multipart/form-data) from the request as a @scala[Seq[(String, String)]]@java[List<Map.Entry<String, String>>]
@refgetRejects all non-GET requests
@refgetFromBrowseableDirectoriesServes the content of the given directories as a file-system browser, i.e. files are sent and directories served as browseable listings
@refgetFromBrowseableDirectoryServes the content of the given directory as a file-system browser, i.e. files are sent and directories served as browseable listings
@refgetFromDirectoryCompletes GET requests with the content of a file underneath a given file-system directory
@refgetFromFileCompletes GET requests with the content of a given file
@refgetFromResourceCompletes GET requests with the content of a given class-path resource
@refgetFromResourceDirectoryCompletes GET requests with the content of a file underneath a given “class-path resource directory”
@refhandleExceptionsTransforms exceptions thrown during evaluation of the inner route using the given @apidoc[ExceptionHandler]
@refhandleRejectionsTransforms rejections produced by the inner route using the given RejectionHandler
@refhandleWebSocketMessagesHandles websocket requests with the given handler and rejects other requests with an @apidoc[ExpectedWebSocketRequestRejection$]
@refhandleWebSocketMessagesForOptionalProtocolHandles websocket requests with the given handler if the subprotocol matches and rejects other requests. If the subprotocol parameter is @scala[None]@java[empty] any WebSocket request is accepted..
@refhandleWebSocketMessagesForProtocolHandles websocket requests with the given handler if the subprotocol matches and rejects other requests with an @apidoc[ExpectedWebSocketRequestRejection$] or an @apidoc[UnsupportedWebSocketSubprotocolRejection].
@refhandleWithCompletes the request using a given function
@refheadRejects all non-HEAD requests
@refheaderValueExtracts an HTTP header value using a given @scala[HttpHeader => Option[T]]@java[Function<HttpHeader, Optional<T>>] function
@refheaderValueByNameExtracts the value of the first HTTP request header with a given name
@refheaderValueByTypeExtracts the first HTTP request header of the given type
@refheaderValuePFExtracts an HTTP header value using a given @scala[PartialFunction[HttpHeader, T]]]@java[PartialFunction<HttpHeader, T>]
@refhostRejects all requests with a non-matching host name
@refignoreTrailingSlashRetries the inner route adding (or removing) the trailing slash in case of empty rejections
@reflistDirectoryContentsCompletes GET requests with a unified listing of the contents of all given file-system directories
@reflogRequestProduces a log entry for every incoming request
@reflogRequestResultProduces a log entry for every incoming request and @apidoc[RouteResult]
@reflogResultProduces a log entry for every @apidoc[RouteResult]
@refmapInnerRouteTransforms its inner @scala[@scaladocRoute]@java[@javadocRoute] with a @scala[Route => Route]@java[UnaryOperator<Route>] function
@refmapRejectionsTransforms rejections from a previous route with an @scala[immutable.Seq[Rejection] => immutable.Seq[Rejection]]@java[UnaryOperator<List<Rejection>>] function
@refmapRequestTransforms the request with an @scala[HttpRequest => HttpRequest]@java[UnaryOperator<HttpRequest>] function
@refmapRequestContextTransforms the @apidoc[RequestContext] with a @scala[RequestContext => RequestContext]@java[UnaryOperator<RequestContext>] function
@refmapResponseTransforms the response with an @scala[HttpResponse => HttpResponse]@java[UnaryOperator<HttpResponse>] function
@refmapResponseEntityTransforms the response entity with an @scala[ResponseEntity => ResponseEntity]@java[UnaryOperator<ResponseEntity>] function
@refmapResponseHeadersTransforms the response headers with an @scala[immutable.Seq[HttpHeader] => immutable.Seq[HttpHeader]]@java[UnaryOperator<List<HttpHeader>>] function
@refmapRouteResultTransforms the @apidoc[RouteResult] with a @scala[RouteResult => RouteResult]@java[UnaryOperator<RouteResult>] function
@refmapRouteResultFutureTransforms the @apidoc[RouteResult] future with a @scala[Future[RouteResult] => Future[RouteResult]]@java[UnaryOperator<CompletionStage<RouteResult>>] function
@refmapRouteResultPFTransforms the @apidoc[RouteResult] with a @scala[PartialFunction[RouteResult, RouteResult]]@java[PartialFunction<RouteResult, RouteResult>]
@refmapRouteResultWithTransforms the @apidoc[RouteResult] with a @scala[RouteResult => Future[RouteResult]]@java[Function<RouteResult, CompletionStage<RouteResult>>] function
@refmapRouteResultWithPFTransforms the @apidoc[RouteResult] with a @scala[PartialFunction[RouteResult, Future[RouteResult]]]@java[PartialFunction<RouteResult, CompletionStage<RouteResult>>]
@refmapSettingsTransforms the @apidoc[RoutingSettings] with a @scala[RoutingSettings => RoutingSettings]@java[UnaryOperator<RoutingSettings>] function
@refmapUnmatchedPathTransforms the unmatchedPath of the @apidoc[RequestContext] using a @scala[Uri.Path => Uri.Path]@java[UnaryOperator<Uri.Path>] function
@refmethodRejects all requests whose HTTP method does not match the given one
@refonComplete“Unwraps” a @scala[Future[T]]@java[CompletionStage<T>] and runs the inner route after future completion with the future's value as an extraction of type @scala[Try[T]]@java[Try<T>]
@refonCompleteWithBreaker“Unwraps” a @scala[Future[T]]@java[CompletionStage<T>] inside a @apidoc[CircuitBreaker] and runs the inner route after future completion with the future's value as an extraction of type @scala[Try[T]]@java[Try<T>]
@refonSuccess“Unwraps” a @scala[Future[T]]@java[CompletionStage<T>] and runs the inner route after future completion with the future's value as an extraction of type T
@refoptionalAttributeExtracts the value of an optional request attribute with a given key
@refoptionalCookieExtracts the @apidoc[HttpCookiePair] with the given name as an @scala[Option[HttpCookiePair]]@java[Optional<HttpCookiePair>]
@refoptionalHeaderValueExtracts an optional HTTP header value using a given @scala[HttpHeader => Option[T]]@java[Function<HttpHeader, Optional<T>>] function
@refoptionalHeaderValueByNameExtracts the value of the first optional HTTP request header with a given name
@refoptionalHeaderValueByTypeExtracts the first optional HTTP request header of the given type
@refoptionalHeaderValuePFExtracts an optional HTTP header value using a given @scala[PartialFunction[HttpHeader, T]]@java[PartialFunction<HttpHeader, T>]
@refoptionsRejects all non-OPTIONS requests
@refoverrideMethodWithParameterChanges the request method to the value of the specified query parameter
@refparameterExtracts a query parameter value from the request
@refparameterMapExtracts the request's query parameters as a @scala[Map[String, String]]@java[Map<String, String>]
@refparameterMultiMapExtracts the request's query parameters as a @scala[Map[String, List[String]]]@java[Map<String, List<String>>]
@scala[@refparameters]@scala[Extracts a number of query parameter values from the request]
@refparameterSeqExtracts the request's query parameters as a @scala[Seq[(String, String)]]@java[List<Map.Entry<String, String>>]
@refpassAlways simply passes the request on to its inner route, i.e. doesn't do anything, neither with the request nor the response
@refpatchRejects all non-PATCH requests
@refpathApplies the given PathMatcher to the remaining unmatched path after consuming a leading slash
@refpathEndOnly passes on the request to its inner route if the request path has been matched completely
@refpathEndOrSingleSlashOnly passes on the request to its inner route if the request path has been matched completely or only consists of exactly one remaining slash
@refpathPrefixApplies the given PathMatcher to a prefix of the remaining unmatched path after consuming a leading slash
@refpathPrefixTestChecks whether the unmatchedPath has a prefix matched by the given PathMatcher after implicitly consuming a leading slash
@refpathSingleSlashOnly passes on the request to its inner route if the request path consists of exactly one remaining slash
@refpathSuffixApplies the given PathMatcher to a suffix of the remaining unmatched path (Caution: check @scala[scaladoc]@java[java]!)
@refpathSuffixTestChecks whether the unmatched path has a suffix matched by the given PathMatcher (Caution: check @scala[scaladoc]@java[java]!)
@refpostRejects all non-POST requests
@refprovideInjects a given value into a directive
@refputRejects all non-PUT requests
@refqueryRejects all non-QUERY requests
@refrawPathPrefixApplies the given matcher directly to a prefix of the unmatched path of the @apidoc[RequestContext], without implicitly consuming a leading slash
@refrawPathPrefixTestChecks whether the unmatchedPath has a prefix matched by the given PathMatcher
@refrecoverRejectionsTransforms rejections from the inner route with an @scala[immutable.Seq[Rejection] => RouteResult]@java[Function<List<Rejection>, RouteResult>] function
@refrecoverRejectionsWithTransforms rejections from the inner route with an @scala[immutable.Seq[Rejection] => Future[RouteResult]]@java[Function<List<Rejection], CompletionStage<RouteResult>>] function
@refredirectCompletes the request with redirection response of the given type to the given URI
@refredirectToNoTrailingSlashIfPresentIf the request path ends with a slash, redirects to the same URI without trailing slash in the path
@refredirectToTrailingSlashIfMissingIf the request path doesn't end with a slash, redirects to the same URI with trailing slash in the path
@refrejectRejects the request with the given rejections
@refrejectEmptyResponseConverts responses with an empty entity into (empty) rejections
@refrequestEncodedWithRejects the request with an @apidoc[UnsupportedRequestEncodingRejection] if its encoding doesn't match the given one
@refrequestEntityEmptyRejects if the request entity is non-empty
@refrequestEntityPresentRejects with a @apidoc[RequestEntityExpectedRejection$] if the request entity is empty
@refrespondWithDefaultHeaderAdds a given response header if the response doesn't already contain a header with the same name
@refrespondWithDefaultHeadersAdds the subset of the given headers to the response which doesn't already have a header with the respective name present in the response
@refrespondWithHeaderUnconditionally adds a given header to the outgoing response
@refrespondWithHeadersUnconditionally adds the given headers to the outgoing response
@refresponseEncodingAcceptedRejects the request with an @apidoc[UnacceptedResponseEncodingRejection] if the given response encoding is not accepted by the client
@refschemeRejects all requests whose URI scheme doesn't match the given one
@refselectPreferredLanguageInspects the request's Accept-Language header and determines, which of a given set of language alternatives is preferred by the client
@refsetCookieAdds a Set-Cookie response header with the given cookies
@refstoreUploadedFileStreams one uploaded file from a multipart request to a file on disk
@refstoreUploadedFilesStreams all uploaded files from a multipart request to files on disk
@scala[@reftextract]@scala[Extracts a number of values using a RequestContext => Tuple function]
@scala[@reftprovide]@scala[Injects a given tuple of values into a directive]
@refvalidateChecks a given condition before running its inner route
@refwithoutRequestTimeoutDisables @refrequest timeouts for a given route.
@refwithoutSizeLimitSkips request entity size check
@refwithExecutionContextRuns its inner route with the given alternative ExecutionContext
@refwithLogRuns its inner route with the given alternative @apidoc[LoggingAdapter]
@refwithMaterializerRuns its inner route with the given alternative @apidoc[Materializer]
@refwithPrecompressedMediaTypeSupportAdds a Content-Encoding: gzip response header if the entity's media-type is precompressed with gzip header
@refwithRangeSupportAdds Accept-Ranges: bytes to responses to GET requests, produces partial responses if the initial request contained a valid Range header
@refwithRequestTimeoutConfigures the @refrequest timeouts for a given route.
@refwithRequestTimeoutResponsePrepares the @apidoc[HttpResponse] that is emitted if a request timeout is triggered. RequestContext => RequestContext function
@refwithSettingsRuns its inner route with the given alternative @apidoc[RoutingSettings]
@refwithSizeLimitApplies request entity size check