Class PathDirectives
- java.lang.Object
-
- akka.http.javadsl.server.directives.BasicDirectives
-
- akka.http.javadsl.server.directives.CacheConditionDirectives
-
- akka.http.javadsl.server.directives.CodingDirectives
-
- akka.http.javadsl.server.directives.CookieDirectives
-
- akka.http.javadsl.server.directives.DebuggingDirectives
-
- akka.http.javadsl.server.directives.ExecutionDirectives
-
- akka.http.javadsl.server.directives.FileAndResourceDirectives
-
- akka.http.javadsl.server.directives.FileUploadDirectives
-
- akka.http.javadsl.server.directives.FormFieldDirectives
-
- akka.http.javadsl.server.directives.FutureDirectives
-
- akka.http.javadsl.server.directives.HeaderDirectives
-
- akka.http.javadsl.server.directives.AttributeDirectives
-
- akka.http.javadsl.server.directives.HostDirectives
-
- akka.http.javadsl.server.directives.MarshallingDirectives
-
- akka.http.javadsl.server.directives.MethodDirectives
-
- akka.http.javadsl.server.directives.MiscDirectives
-
- akka.http.javadsl.server.directives.ParameterDirectives
-
- akka.http.javadsl.server.directives.PathDirectives
-
- Direct Known Subclasses:
RangeDirectives
public abstract class PathDirectives extends ParameterDirectives
Only path prefixes are matched by these methods, since any kind of chaining path extractions in Java would just look cumbersome without operator overloads; hence, no PathMatcher for Java.Just nest path() directives with the required types, ending in pathEnd() if you want to fail further paths.
-
-
Constructor Summary
Constructors Constructor Description PathDirectives()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Route
ignoreTrailingSlash(java.util.function.Supplier<Route> inner)
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.Route
path(PathMatcher0 p, java.util.function.Supplier<Route> inner)
Applies the givenPathMatcher0
to the remaining unmatched path after consuming a leading slash.<T> Route
path(PathMatcher1<T> p, java.util.function.Function<T,Route> inner)
<T1,T2>
Routepath(PathMatcher2<T1,T2> p, java.util.function.BiFunction<T1,T2,Route> inner)
<T> Route
path(Unmarshaller<java.lang.String,T> t, java.util.function.Function<T,Route> inner)
Consumes a leading slash and extracts the next path segment, unmarshalling it and passing the result to the inner function, expecting the full path to have been consumed then.Route
path(java.lang.String segment, java.util.function.Supplier<Route> inner)
Matches a prefix to the remaining unmatched path after consuming a leading slash.Route
path(java.util.function.Function<java.lang.String,Route> inner)
Route
pathEnd(java.util.function.Supplier<Route> inner)
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.Route
pathEndOrSingleSlash(java.util.function.Supplier<Route> inner)
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.Route
pathPrefix(PathMatcher0 p, java.util.function.Supplier<Route> inner)
Applies the givenPathMatcher0
to the remaining unmatched path after consuming a leading slash.<T> Route
pathPrefix(PathMatcher1<T> p, java.util.function.Function<T,Route> inner)
<T1,T2>
RoutepathPrefix(PathMatcher2<T1,T2> p, java.util.function.BiFunction<T1,T2,Route> inner)
<T> Route
pathPrefix(Unmarshaller<java.lang.String,T> t, java.util.function.Function<T,Route> inner)
Consumes a leading slash and extracts the next path segment, unmarshalling it and passing the result to the inner function.Route
pathPrefix(java.lang.String segment, java.util.function.Supplier<Route> inner)
Matches a prefix to the remaining unmatched path after consuming a leading slash.Route
pathPrefix(java.util.function.Function<java.lang.String,Route> inner)
Route
pathPrefixTest(PathMatcher0 pm, java.util.function.Supplier<Route> inner)
<T1> Route
pathPrefixTest(PathMatcher1<T1> pm, java.util.function.Function<T1,Route> inner)
<T1,T2>
RoutepathPrefixTest(PathMatcher2<T1,T2> pm, java.util.function.BiFunction<T1,T2,Route> inner)
Route
pathPrefixTest(java.lang.String segment, java.util.function.Supplier<Route> inner)
Checks whether the unmatchedPath of theRequestContext
has a prefix matched by the given PathMatcher.Route
pathSingleSlash(java.util.function.Supplier<Route> inner)
Only passes on the request to its inner route if the request path consists of exactly one remaining slash.Route
pathSuffix(PathMatcher0 pm, java.util.function.Supplier<Route> inner)
<T1> Route
pathSuffix(PathMatcher1<T1> pm, java.util.function.Function<T1,Route> inner)
<T1,T2>
RoutepathSuffix(PathMatcher2<T1,T2> pm, java.util.function.BiFunction<T1,T2,Route> inner)
Route
pathSuffix(java.lang.String segment, java.util.function.Supplier<Route> inner)
Applies the givenPathMatcher
to a suffix of the remaining unmatchedPath of theRequestContext
.Route
pathSuffixTest(PathMatcher0 pm, java.util.function.Supplier<Route> inner)
<T1> Route
pathSuffixTest(PathMatcher1<T1> pm, java.util.function.Function<T1,Route> inner)
<T1,T2>
RoutepathSuffixTest(PathMatcher2<T1,T2> pm, java.util.function.BiFunction<T1,T2,Route> inner)
Route
pathSuffixTest(java.lang.String segment, java.util.function.Supplier<Route> inner)
Checks whether the unmatchedPath of theRequestContext
has a suffix matched by the given PathMatcher.Route
rawPathPrefix(PathMatcher0 pm, java.util.function.Supplier<Route> inner)
<T1> Route
rawPathPrefix(PathMatcher1<T1> pm, java.util.function.Function<T1,Route> inner)
<T1,T2>
RouterawPathPrefix(PathMatcher2<T1,T2> pm, java.util.function.BiFunction<T1,T2,Route> inner)
Route
rawPathPrefix(java.lang.String segment, java.util.function.Supplier<Route> inner)
Applies the given matcher directly to a prefix of the unmatched path of theRequestContext
(i.e. without implicitly consuming a leading slash).Route
rawPathPrefixTest(PathMatcher0 pm, java.util.function.Supplier<Route> inner)
<T1> Route
rawPathPrefixTest(PathMatcher1<T1> pm, java.util.function.Function<T1,Route> inner)
<T1,T2>
RouterawPathPrefixTest(PathMatcher2<T1,T2> pm, java.util.function.BiFunction<T1,T2,Route> inner)
Route
rawPathPrefixTest(java.lang.String segment, java.util.function.Supplier<Route> inner)
Checks whether the unmatchedPath of theRequestContext
has a prefix matched by the given PathMatcher.Route
redirectToNoTrailingSlashIfPresent(StatusCode redirectionType, java.util.function.Supplier<Route> inner)
If the request path ends with a slash, redirect to the same uri without trailing slash in the path.Route
redirectToTrailingSlashIfMissing(StatusCode redirectionType, java.util.function.Supplier<Route> inner)
If the request path doesn't end with a slash, redirect to the same uri with trailing slash in the path.-
Methods inherited from class akka.http.javadsl.server.directives.ParameterDirectives
parameter, parameter, parameterList, parameterList, parameterList, parameterMap, parameterMultiMap, parameterOptional, parameterOptional, parameterOrDefault, parameterRequiredValue
-
Methods inherited from class akka.http.javadsl.server.directives.MiscDirectives
extractClientIP, rejectEmptyResponse, requestEntityEmpty, requestEntityPresent, selectPreferredLanguage, validate, withoutSizeLimit, withSizeLimit
-
Methods inherited from class akka.http.javadsl.server.directives.MethodDirectives
delete, extractMethod, get, head, method, options, overrideMethodWithParameter, patch, post, put
-
Methods inherited from class akka.http.javadsl.server.directives.MarshallingDirectives
completeWith, entity, handleWith, request
-
Methods inherited from class akka.http.javadsl.server.directives.HostDirectives
extractHost, host, host, host, host
-
Methods inherited from class akka.http.javadsl.server.directives.AttributeDirectives
attribute, optionalAttribute
-
Methods inherited from class akka.http.javadsl.server.directives.HeaderDirectives
checkSameOrigin, headerValue, headerValueByName, headerValueByType, headerValuePF, optionalHeaderValue, optionalHeaderValueByName, optionalHeaderValueByType, optionalHeaderValuePF
-
Methods inherited from class akka.http.javadsl.server.directives.FutureDirectives
completeOrRecoverWith, onComplete, onComplete, onCompleteWithBreaker, onSuccess, onSuccess
-
Methods inherited from class akka.http.javadsl.server.directives.FormFieldDirectives
formField, formField, formFieldList, formFieldList, formFieldList, formFieldMap, formFieldMultiMap, formFieldOptional, formFieldOptional
-
Methods inherited from class akka.http.javadsl.server.directives.FileUploadDirectives
fileUpload, fileUploadAll, storeUploadedFile, storeUploadedFiles
-
Methods inherited from class akka.http.javadsl.server.directives.FileAndResourceDirectives
defaultContentTypeResolver, defaultDirectoryRenderer, getFromBrowseableDirectories, getFromBrowseableDirectories, getFromBrowseableDirectories, getFromBrowseableDirectories, getFromBrowseableDirectories, getFromBrowseableDirectory, getFromBrowseableDirectory, getFromBrowseableDirectory, getFromBrowseableDirectory, getFromDirectory, getFromDirectory, getFromFile, getFromFile, getFromFile, getFromFile, getFromFile, getFromResource, getFromResource, getFromResource, getFromResource, getFromResourceDirectory, getFromResourceDirectory, getFromResourceDirectory, getFromResourceDirectory, listDirectoryContents, listDirectoryContents, listDirectoryContents, listDirectoryContents
-
Methods inherited from class akka.http.javadsl.server.directives.ExecutionDirectives
handleExceptions, handleRejections
-
Methods inherited from class akka.http.javadsl.server.directives.DebuggingDirectives
logRequest, logRequest, logRequest, logRequestResult, logRequestResultOptional, logResult, logResult, logResult
-
Methods inherited from class akka.http.javadsl.server.directives.CookieDirectives
cookie, deleteCookie, deleteCookie, deleteCookie, deleteCookie, deleteCookie, optionalCookie, setCookie, setCookie
-
Methods inherited from class akka.http.javadsl.server.directives.CodingDirectives
decodeRequest, decodeRequestWith, decodeRequestWith, encodeResponse, encodeResponseWith, requestEncodedWith, responseEncodingAccepted, withPrecompressedMediaTypeSupport
-
Methods inherited from class akka.http.javadsl.server.directives.CacheConditionDirectives
conditional, conditional, conditional, conditional
-
Methods inherited from class akka.http.javadsl.server.directives.BasicDirectives
cancelRejection, cancelRejections, cancelRejections, extract, extractActorSystem, extractDataBytes, extractEntity, extractExecutionContext, extractLog, extractMatchedPath, extractMaterializer, extractParserSettings, extractRequest, extractRequestContext, extractRequestEntity, extractSettings, extractStrictEntity, extractStrictEntity, extractUnmatchedPath, extractUri, mapInnerRoute, mapRejections, mapRequest, mapRequestContext, mapResponse, mapResponseEntity, mapResponseHeaders, mapRouteResult, mapRouteResultFuture, mapRouteResultPF, mapRouteResultWith, mapRouteResultWithPF, mapSettings, mapUnmatchedPath, pass, provide, recoverRejections, recoverRejectionsWith, toStrictEntity, toStrictEntity, withExecutionContext, withLog, withMaterializer, withSettings
-
-
-
-
Method Detail
-
ignoreTrailingSlash
public Route ignoreTrailingSlash(java.util.function.Supplier<Route> inner)
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.- Parameters:
inner
- (undocumented)- Returns:
- (undocumented)
-
path
public Route path(java.lang.String segment, java.util.function.Supplier<Route> inner)
Matches a prefix to the remaining unmatched path after consuming a leading slash. The matcher has to match the remaining path completely. If matched the value matching the prefix is extracted on the directive level.- Parameters:
segment
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
path
public Route path(PathMatcher0 p, java.util.function.Supplier<Route> inner)
Applies the givenPathMatcher0
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 thePathMatcher0
is extracted on the directive level.- Parameters:
p
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
path
public <T> Route path(PathMatcher1<T> p, java.util.function.Function<T,Route> inner)
-
path
public <T1,T2> Route path(PathMatcher2<T1,T2> p, java.util.function.BiFunction<T1,T2,Route> inner)
-
path
public <T> Route path(Unmarshaller<java.lang.String,T> t, java.util.function.Function<T,Route> inner)
Consumes a leading slash and extracts the next path segment, unmarshalling it and passing the result to the inner function, expecting the full path to have been consumed then.- Parameters:
t
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
pathEnd
public Route pathEnd(java.util.function.Supplier<Route> inner)
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.- Parameters:
inner
- (undocumented)- Returns:
- (undocumented)
-
pathEndOrSingleSlash
public Route pathEndOrSingleSlash(java.util.function.Supplier<Route> inner)
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.javadsl.model.StatusCode, java.util.function.Supplier<akka.http.javadsl.server.Route>)
orredirectToNoTrailingSlashIfPresent(akka.http.javadsl.model.StatusCode, java.util.function.Supplier<akka.http.javadsl.server.Route>)
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: http://googlewebmastercentral.blogspot.de/2010/04/to-slash-or-not-to-slash.html
- Parameters:
inner
- (undocumented)- Returns:
- (undocumented)
-
pathPrefix
public Route pathPrefix(java.lang.String segment, java.util.function.Supplier<Route> inner)
Matches a prefix to the remaining unmatched path after consuming a leading slash. The matcher has to match a prefix of the remaining path. If matched the value matching the prefix is extracted on the directive level.- Parameters:
segment
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
pathPrefix
public Route pathPrefix(PathMatcher0 p, java.util.function.Supplier<Route> inner)
Applies the givenPathMatcher0
to 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:
p
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
pathPrefix
public <T> Route pathPrefix(PathMatcher1<T> p, java.util.function.Function<T,Route> inner)
-
pathPrefix
public <T1,T2> Route pathPrefix(PathMatcher2<T1,T2> p, java.util.function.BiFunction<T1,T2,Route> inner)
-
pathPrefix
public <T> Route pathPrefix(Unmarshaller<java.lang.String,T> t, java.util.function.Function<T,Route> inner)
Consumes a leading slash and extracts the next path segment, unmarshalling it and passing the result to the inner function.- Parameters:
t
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
pathPrefixTest
public Route pathPrefixTest(java.lang.String segment, java.util.function.Supplier<Route> inner)
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:
segment
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
pathPrefixTest
public Route pathPrefixTest(PathMatcher0 pm, java.util.function.Supplier<Route> inner)
-
pathPrefixTest
public <T1> Route pathPrefixTest(PathMatcher1<T1> pm, java.util.function.Function<T1,Route> inner)
-
pathPrefixTest
public <T1,T2> Route pathPrefixTest(PathMatcher2<T1,T2> pm, java.util.function.BiFunction<T1,T2,Route> inner)
-
pathSingleSlash
public Route pathSingleSlash(java.util.function.Supplier<Route> inner)
Only passes on the request to its inner route if the request path consists of exactly one remaining slash.- Parameters:
inner
- (undocumented)- Returns:
- (undocumented)
-
pathSuffix
public Route pathSuffix(java.lang.String segment, java.util.function.Supplier<Route> inner)
Applies the givenPathMatcher
to a suffix of the remaining unmatchedPath of theRequestContext
. If matched the value extracted by thePathMatcher0
is extracted and the matched parts of the path are consumed. Note that, for efficiency reasons, the givenPathMatcher0
must match the desired suffix in reversed-segment order, i.e.pathSuffix("baz" / "bar")
would match/foo/bar/baz
!- Parameters:
segment
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
pathSuffix
public Route pathSuffix(PathMatcher0 pm, java.util.function.Supplier<Route> inner)
-
pathSuffix
public <T1> Route pathSuffix(PathMatcher1<T1> pm, java.util.function.Function<T1,Route> inner)
-
pathSuffix
public <T1,T2> Route pathSuffix(PathMatcher2<T1,T2> pm, java.util.function.BiFunction<T1,T2,Route> inner)
-
pathSuffixTest
public Route pathSuffixTest(java.lang.String segment, java.util.function.Supplier<Route> inner)
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:
segment
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
pathSuffixTest
public Route pathSuffixTest(PathMatcher0 pm, java.util.function.Supplier<Route> inner)
-
pathSuffixTest
public <T1> Route pathSuffixTest(PathMatcher1<T1> pm, java.util.function.Function<T1,Route> inner)
-
pathSuffixTest
public <T1,T2> Route pathSuffixTest(PathMatcher2<T1,T2> pm, java.util.function.BiFunction<T1,T2,Route> inner)
-
rawPathPrefix
public Route rawPathPrefix(java.lang.String segment, java.util.function.Supplier<Route> inner)
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:
segment
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
rawPathPrefix
public Route rawPathPrefix(PathMatcher0 pm, java.util.function.Supplier<Route> inner)
-
rawPathPrefix
public <T1> Route rawPathPrefix(PathMatcher1<T1> pm, java.util.function.Function<T1,Route> inner)
-
rawPathPrefix
public <T1,T2> Route rawPathPrefix(PathMatcher2<T1,T2> pm, java.util.function.BiFunction<T1,T2,Route> inner)
-
rawPathPrefixTest
public Route rawPathPrefixTest(java.lang.String segment, java.util.function.Supplier<Route> inner)
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:
segment
- (undocumented)inner
- (undocumented)- Returns:
- (undocumented)
-
rawPathPrefixTest
public Route rawPathPrefixTest(PathMatcher0 pm, java.util.function.Supplier<Route> inner)
-
rawPathPrefixTest
public <T1> Route rawPathPrefixTest(PathMatcher1<T1> pm, java.util.function.Function<T1,Route> inner)
-
rawPathPrefixTest
public <T1,T2> Route rawPathPrefixTest(PathMatcher2<T1,T2> pm, java.util.function.BiFunction<T1,T2,Route> inner)
-
redirectToNoTrailingSlashIfPresent
public Route redirectToNoTrailingSlashIfPresent(StatusCode redirectionType, java.util.function.Supplier<Route> inner)
If the request path ends with a slash, redirect to the same uri without trailing slash in the path.'''Caveat''':
pathSingleSlash(java.util.function.Supplier<akka.http.javadsl.server.Route>)
directive will not match inside of this directive.- Parameters:
redirectionType
- A status code from StatusCodes, which must be a redirection type.inner
- (undocumented)- Returns:
- (undocumented)
-
redirectToTrailingSlashIfMissing
public Route redirectToTrailingSlashIfMissing(StatusCode redirectionType, java.util.function.Supplier<Route> inner)
If the request path doesn't end with a slash, redirect to the same uri with trailing slash in the path.'''Caveat''':
path(java.lang.String, java.util.function.Supplier<akka.http.javadsl.server.Route>)
without trailing slash andpathEnd(java.util.function.Supplier<akka.http.javadsl.server.Route>)
directives will not match inside of this directive.- Parameters:
redirectionType
- A status code from StatusCodes, which must be a redirection type.inner
- (undocumented)- Returns:
- (undocumented)
-
-