extractScheme • Akka HTTP (original) (raw)

Signature

def extractScheme: Directive1[String]

Description

Extracts the Uri scheme (i.e. “http”, “https”, etc.) for an incoming request.

For rejecting a request if it doesn’t match a specified scheme name, see the scheme directive.

Example

Scala

source`val route = extractScheme { scheme => complete(s"The scheme is '${scheme}'") }

// tests: Get("https://www.example.com/") ~> route ~> check { responseAs[String] shouldEqual "The scheme is 'https'" }`

Java

source`import static akka.http.javadsl.server.Directives.complete; import static akka.http.javadsl.server.Directives.extractScheme;

final Route route = extractScheme((scheme) -> complete(String.format("The scheme is '%s'", scheme))); testRoute(route).run(HttpRequest.GET("https://www.example.com/")) .assertEntity("The scheme is 'https'");`

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.