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 org.apache.pekko.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");