Interface PathDirectives

    • Method Detail

      • path

        <L> Directive<L> path​(PathMatcher<L> pm)
        Applies the given PathMatcher to the remaining unmatched path after consuming a leading slash. The matcher has to match the remaining path completely. If matched the value extracted by the PathMatcher is extracted on the directive level.

        Parameters:
        pm - (undocumented)
        Returns:
        (undocumented)
      • pathPrefix

        <L> Directive<L> pathPrefix​(PathMatcher<L> pm)
        Applies the given PathMatcher to a prefix of the remaining unmatched path after consuming a leading slash. The matcher has to match a prefix of the remaining path. If matched the value extracted by the PathMatcher is extracted on the directive level.

        Parameters:
        pm - (undocumented)
        Returns:
        (undocumented)
      • rawPathPrefix

        <L> Directive<L> rawPathPrefix​(PathMatcher<L> pm)
        Applies the given matcher directly to a prefix of the unmatched path of the RequestContext (i.e. without implicitly consuming a leading slash). The matcher has to match a prefix of the remaining path. If matched the value extracted by the PathMatcher is extracted on the directive level.

        Parameters:
        pm - (undocumented)
        Returns:
        (undocumented)
      • pathPrefixTest

        <L> Directive<L> pathPrefixTest​(PathMatcher<L> pm)
        Checks whether the unmatchedPath of the RequestContext has a prefix matched by the given PathMatcher. In analogy to the pathPrefix directive a leading slash is implied.

        Parameters:
        pm - (undocumented)
        Returns:
        (undocumented)
      • rawPathPrefixTest

        <L> Directive<L> rawPathPrefixTest​(PathMatcher<L> pm)
        Checks whether the unmatchedPath of the RequestContext has a prefix matched by the given PathMatcher. However, as opposed to the pathPrefix directive the matched path is not actually "consumed".

        Parameters:
        pm - (undocumented)
        Returns:
        (undocumented)
      • pathSuffix

        <L> Directive<L> pathSuffix​(PathMatcher<L> pm)
        Applies the given PathMatcher to a suffix of the remaining unmatchedPath of the RequestContext. If matched the value extracted by the PathMatcher is extracted and the matched parts of the path are consumed. Note that, for efficiency reasons, the given PathMatcher must match the desired suffix in reversed-segment order, i.e. pathSuffix("baz" / "bar") would match /foo/bar/baz!

        Parameters:
        pm - (undocumented)
        Returns:
        (undocumented)
      • pathSuffixTest

        <L> Directive<L> pathSuffixTest​(PathMatcher<L> pm)
        Checks whether the unmatchedPath of the RequestContext has a suffix matched by the given PathMatcher. However, as opposed to the pathSuffix directive the matched path is not actually "consumed". Note that, for efficiency reasons, the given PathMatcher must match the desired suffix in reversed-segment order, i.e. pathSuffixTest("baz" / "bar") would match /foo/bar/baz!

        Parameters:
        pm - (undocumented)
        Returns:
        (undocumented)
      • pathEnd

        Directive<scala.runtime.BoxedUnit> pathEnd()
        Rejects the request if the unmatchedPath of the RequestContext is non-empty, or said differently: only passes on the request to its inner route if the request path has been matched completely.

        Returns:
        (undocumented)
      • pathEndOrSingleSlash

        Directive<scala.runtime.BoxedUnit> pathEndOrSingleSlash()
        Only passes on the request to its inner route if the request path has been matched completely or only consists of exactly one remaining slash.

        Note that trailing slash and non-trailing slash URLs are '''not''' the same, although they often serve the same content. It is recommended to serve only one URL version and make the other redirect to it using redirectToTrailingSlashIfMissing(akka.http.scaladsl.model.StatusCodes.Redirection) or redirectToNoTrailingSlashIfPresent(akka.http.scaladsl.model.StatusCodes.Redirection) directive.

        For example:

        
         def route = {
           // redirect '/users/' to '/users', '/users/:userId/' to '/users/:userId'
           redirectToNoTrailingSlashIfPresent(Found) {
             pathPrefix("users") {
               concat(
                 pathEnd {
                   // user list ...
                 },
                 path(UUID) { userId =>
                   // user profile ...
                 }
               )
             }
           }
         }
         

        For further information, refer to:

        Returns:
        (undocumented)
        See Also:
      • pathSingleSlash

        Directive<scala.runtime.BoxedUnit> pathSingleSlash()
        Only passes on the request to its inner route if the request path consists of exactly one remaining slash.

        Returns:
        (undocumented)
      • redirectToTrailingSlashIfMissing

        Directive<scala.runtime.BoxedUnit> redirectToTrailingSlashIfMissing​(StatusCodes.Redirection redirectionType)
        If the request path doesn't end with a slash, redirect to the same uri with trailing slash in the path.

        '''Caveat''': <L>path(akka.http.scaladsl.server.PathMatcher<L>) without trailing slash and pathEnd() directives will not match inside of this directive.

        Parameters:
        redirectionType - (undocumented)
        Returns:
        (undocumented)
      • redirectToNoTrailingSlashIfPresent

        Directive<scala.runtime.BoxedUnit> redirectToNoTrailingSlashIfPresent​(StatusCodes.Redirection redirectionType)
        If the request path ends with a slash, redirect to the same uri without trailing slash in the path.

        Note, however, that this directive doesn't apply to a URI consisting of just a single slash. HTTP does not support empty target paths, so that browsers will convert a URI such as http://example.org to http://example.org/ adding the trailing slash.

        Redirecting the single slash path URI would lead to a redirection loop.

        '''Caveat''': pathSingleSlash() directive will only match on the root path level inside of this directive.

        Parameters:
        redirectionType - (undocumented)
        Returns:
        (undocumented)
      • ignoreTrailingSlash

        Directive<scala.runtime.BoxedUnit> ignoreTrailingSlash()
        Tries to match the inner route and if it fails with an empty rejection, it tries it again adding (or removing) the trailing slash on the given path.

        Returns:
        (undocumented)