Interface PathDirectives
-
- All Superinterfaces:
ImplicitPathMatcherConstruction
,PathMatchers
,ToNameReceptacleEnhancements
- All Known Subinterfaces:
Directives
- All Known Implementing Classes:
Directives$
,HttpApp
,PathDirectives$
public interface PathDirectives extends PathMatchers, ImplicitPathMatcherConstruction, ToNameReceptacleEnhancements
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
PathDirectives.TrailingRetryRejection$
INTERNAL API-
Nested classes/interfaces inherited from interface akka.http.scaladsl.server.PathMatchers
PathMatchers.HexIntNumber$, PathMatchers.HexLongNumber$, PathMatchers.IntNumber$, PathMatchers.LongNumber$, PathMatchers.NumberMatcher<T>, PathMatchers.PathEnd$, PathMatchers.Remaining$, PathMatchers.RemainingPath$, PathMatchers.Segment$, PathMatchers.Slash$
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description 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.<L> Directive<L>
path(PathMatcher<L> pm)
Applies the givenPathMatcher
to the remaining unmatched path after consuming a leading slash.Directive<scala.runtime.BoxedUnit>
pathEnd()
Rejects the request if the unmatchedPath of theRequestContext
is non-empty, or said differently: only passes on the request to its inner route if the request path has been matched completely.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.<L> Directive<L>
pathPrefix(PathMatcher<L> pm)
Applies the givenPathMatcher
to a prefix of the remaining unmatched path after consuming a leading slash.<L> Directive<L>
pathPrefixTest(PathMatcher<L> pm)
Checks whether the unmatchedPath of theRequestContext
has a prefix matched by the given PathMatcher.Directive<scala.runtime.BoxedUnit>
pathSingleSlash()
Only passes on the request to its inner route if the request path consists of exactly one remaining slash.<L> Directive<L>
pathSuffix(PathMatcher<L> pm)
Applies the givenPathMatcher
to a suffix of the remaining unmatchedPath of theRequestContext
.<L> Directive<L>
pathSuffixTest(PathMatcher<L> pm)
Checks whether the unmatchedPath of theRequestContext
has a suffix matched by the given PathMatcher.<L> Directive<L>
rawPathPrefix(PathMatcher<L> pm)
Applies the given matcher directly to a prefix of the unmatched path of theRequestContext
(i.e. without implicitly consuming a leading slash).<L> Directive<L>
rawPathPrefixTest(PathMatcher<L> pm)
Checks whether the unmatchedPath of theRequestContext
has a prefix matched by the given PathMatcher.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.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.-
Methods inherited from interface akka.http.scaladsl.server.ImplicitPathMatcherConstruction
_regex2PathMatcher, _segmentStringToPathMatcher, _stringExtractionPair2PathMatcher, _stringNameOptionReceptacle2PathMatcher, _valueMap2PathMatcher
-
Methods inherited from interface akka.http.scaladsl.server.PathMatchers
DoubleNumber, HexIntNumber, HexLongNumber, IntNumber, JavaUUID, LongNumber, Neutral, not, nothingMatcher, PathEnd, Remaining, RemainingPath, Segment, Segments, Segments, Segments, separateOnSlashes, Slash
-
Methods inherited from interface akka.http.scaladsl.common.ToNameReceptacleEnhancements
_string2NR, _symbol2NR
-
-
-
-
Method Detail
-
path
<L> Directive<L> path(PathMatcher<L> pm)
Applies the givenPathMatcher
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 thePathMatcher
is extracted on the directive level.- Parameters:
pm
- (undocumented)- Returns:
- (undocumented)
-
pathPrefix
<L> Directive<L> pathPrefix(PathMatcher<L> pm)
Applies the givenPathMatcher
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 theRequestContext
(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 theRequestContext
has a prefix matched by the given PathMatcher. In analogy to thepathPrefix
directive a leading slash is implied.- Parameters:
pm
- (undocumented)- Returns:
- (undocumented)
-
rawPathPrefixTest
<L> Directive<L> rawPathPrefixTest(PathMatcher<L> pm)
Checks whether the unmatchedPath of theRequestContext
has a prefix matched by the given PathMatcher. However, as opposed to thepathPrefix
directive the matched path is not actually "consumed".- Parameters:
pm
- (undocumented)- Returns:
- (undocumented)
-
pathSuffix
<L> Directive<L> pathSuffix(PathMatcher<L> pm)
Applies the givenPathMatcher
to a suffix of the remaining unmatchedPath of theRequestContext
. If matched the value extracted by thePathMatcher
is extracted and the matched parts of the path are consumed. Note that, for efficiency reasons, the givenPathMatcher
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 theRequestContext
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 theRequestContext
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)
orredirectToNoTrailingSlashIfPresent(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:
-
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 andpathEnd()
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
tohttp://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)
-
-