extractUri

Signature

def extractUri: Directive1[Uri]

Description

Access the full URI of the request.

Use SchemeDirectives, HostDirectives, PathDirectives, and ParameterDirectives for more targeted access to parts of the URI.

Example

Scala
sourceval route =
  extractUri { uri =>
    complete(s"Full URI: $uri")
  }

// tests:
Get("/") ~> route ~> check {
  // tests are executed with the host assumed to be "example.com"
  responseAs[String] shouldEqual "Full URI: http://example.com/"
}
Get("/test") ~> route ~> check {
  responseAs[String] shouldEqual "Full URI: http://example.com/test"
}
Java
sourceimport static akka.http.javadsl.server.Directives.extractUri;

final Route route = extractUri(uri ->
  complete("Full URI: " + uri)
);

// tests:
// tests are executed with the host assumed to be "example.com"
testRoute(route).run(HttpRequest.GET("/"))
  .assertEntity("Full URI: http://example.com/");
testRoute(route).run(HttpRequest.GET("/test"))
  .assertEntity("Full URI: http://example.com/test");
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.