Class PathDirectives
- Direct Known Subclasses:
- RangeDirectives
Just nest path() directives with the required types, ending in pathEnd() if you want to fail further paths.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionignoreTrailingSlash(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.Matches a prefix to the remaining unmatched path after consuming a leading slash.path(PathMatcher0 p, Supplier<Route> inner) Applies the givenPathMatcher0to the remaining unmatched path after consuming a leading slash.<T> Routepath(PathMatcher1<T> p, Function<T, Route> inner) <T1,T2> Route path(PathMatcher2<T1, T2> p, BiFunction<T1, T2, Route> inner) <T> Routepath(Unmarshaller<String, T> t, 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.Rejects the request if the unmatchedPath of thepekko.http.javadsl.server.RequestContextis non-empty, or said differently: only passes on the request to its inner route if the request path has been matched completely.pathEndOrSingleSlash(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.pathPrefix(String segment, Supplier<Route> inner) Matches a prefix to the remaining unmatched path after consuming a leading slash.pathPrefix(Function<String, Route> inner) pathPrefix(PathMatcher0 p, Supplier<Route> inner) Applies the givenPathMatcher0to the remaining unmatched path after consuming a leading slash.<T> RoutepathPrefix(PathMatcher1<T> p, Function<T, Route> inner) <T1,T2> Route pathPrefix(PathMatcher2<T1, T2> p, BiFunction<T1, T2, Route> inner) <T> RoutepathPrefix(Unmarshaller<String, T> t, Function<T, Route> inner) Consumes a leading slash and extracts the next path segment, unmarshalling it and passing the result to the inner function.pathPrefixTest(String segment, Supplier<Route> inner) Checks whether the unmatchedPath of thepekko.http.javadsl.server.RequestContexthas a prefix matched by the given PathMatcher.pathPrefixTest(PathMatcher0 pm, Supplier<Route> inner) <T1> RoutepathPrefixTest(PathMatcher1<T1> pm, Function<T1, Route> inner) <T1,T2> Route pathPrefixTest(PathMatcher2<T1, T2> pm, BiFunction<T1, T2, Route> inner) pathSingleSlash(Supplier<Route> inner) Only passes on the request to its inner route if the request path consists of exactly one remaining slash.pathSuffix(String segment, Supplier<Route> inner) Applies the givenpekko.http.scaladsl.server.PathMatcherto a suffix of the remaining unmatchedPath of thepekko.http.javadsl.server.RequestContext.pathSuffix(PathMatcher0 pm, Supplier<Route> inner) <T1> RoutepathSuffix(PathMatcher1<T1> pm, Function<T1, Route> inner) <T1,T2> Route pathSuffix(PathMatcher2<T1, T2> pm, BiFunction<T1, T2, Route> inner) pathSuffixTest(String segment, Supplier<Route> inner) Checks whether the unmatchedPath of thepekko.http.javadsl.server.RequestContexthas a suffix matched by the given PathMatcher.pathSuffixTest(PathMatcher0 pm, Supplier<Route> inner) <T1> RoutepathSuffixTest(PathMatcher1<T1> pm, Function<T1, Route> inner) <T1,T2> Route pathSuffixTest(PathMatcher2<T1, T2> pm, BiFunction<T1, T2, Route> inner) rawPathPrefix(String segment, Supplier<Route> inner) Applies the given matcher directly to a prefix of the unmatched path of thepekko.http.javadsl.server.RequestContext(i.e. without implicitly consuming a leading slash).rawPathPrefix(PathMatcher0 pm, Supplier<Route> inner) <T1> RouterawPathPrefix(PathMatcher1<T1> pm, Function<T1, Route> inner) <T1,T2> Route rawPathPrefix(PathMatcher2<T1, T2> pm, BiFunction<T1, T2, Route> inner) rawPathPrefixTest(String segment, Supplier<Route> inner) Checks whether the unmatchedPath of thepekko.http.javadsl.server.RequestContexthas a prefix matched by the given PathMatcher.rawPathPrefixTest(PathMatcher0 pm, Supplier<Route> inner) <T1> RouterawPathPrefixTest(PathMatcher1<T1> pm, Function<T1, Route> inner) <T1,T2> Route rawPathPrefixTest(PathMatcher2<T1, T2> pm, BiFunction<T1, T2, Route> inner) redirectToNoTrailingSlashIfPresent(StatusCode redirectionType, Supplier<Route> inner) If the request path ends with a slash, redirect to the same uri without trailing slash in the path.redirectToTrailingSlashIfMissing(StatusCode redirectionType, 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 org.apache.pekko.http.javadsl.server.directives.ParameterDirectivesparameter, parameter, parameterList, parameterList, parameterList, parameterMap, parameterMultiMap, parameterOptional, parameterOptional, parameterOrDefault, parameterRequiredValueMethods inherited from class org.apache.pekko.http.javadsl.server.directives.MiscDirectivesextractClientIP, rejectEmptyResponse, requestEntityEmpty, requestEntityPresent, selectPreferredLanguage, validate, withoutSizeLimit, withSizeLimitMethods inherited from class org.apache.pekko.http.javadsl.server.directives.MethodDirectivesdelete, extractMethod, get, head, method, options, overrideMethodWithParameter, patch, post, putMethods inherited from class org.apache.pekko.http.javadsl.server.directives.MarshallingDirectivescompleteWith, entity, handleWith, requestMethods inherited from class org.apache.pekko.http.javadsl.server.directives.HostDirectivesextractHost, host, host, host, hostMethods inherited from class org.apache.pekko.http.javadsl.server.directives.AttributeDirectivesattribute, optionalAttributeMethods inherited from class org.apache.pekko.http.javadsl.server.directives.HeaderDirectivescheckSameOrigin, headerValue, headerValueByName, headerValueByType, headerValuePF, optionalHeaderValue, optionalHeaderValueByName, optionalHeaderValueByType, optionalHeaderValuePFMethods inherited from class org.apache.pekko.http.javadsl.server.directives.FutureDirectivescompleteOrRecoverWith, onComplete, onComplete, onCompleteWithBreaker, onSuccess, onSuccessMethods inherited from class org.apache.pekko.http.javadsl.server.directives.FormFieldDirectivesformField, formField, formFieldList, formFieldList, formFieldList, formFieldMap, formFieldMultiMap, formFieldOptional, formFieldOptionalMethods inherited from class org.apache.pekko.http.javadsl.server.directives.FileUploadDirectivesfileUpload, fileUploadAll, storeUploadedFile, storeUploadedFilesMethods inherited from class org.apache.pekko.http.javadsl.server.directives.FileAndResourceDirectivesdefaultContentTypeResolver, 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, listDirectoryContentsMethods inherited from class org.apache.pekko.http.javadsl.server.directives.ExecutionDirectiveshandleExceptions, handleRejectionsMethods inherited from class org.apache.pekko.http.javadsl.server.directives.DebuggingDirectiveslogRequest, logRequest, logRequest, logRequestResult, logRequestResultOptional, logResult, logResult, logResultMethods inherited from class org.apache.pekko.http.javadsl.server.directives.CookieDirectivescookie, deleteCookie, deleteCookie, deleteCookie, deleteCookie, deleteCookie, optionalCookie, setCookie, setCookieMethods inherited from class org.apache.pekko.http.javadsl.server.directives.CodingDirectivesdecodeRequest, decodeRequestWith, decodeRequestWith, encodeResponse, encodeResponseWith, requestEncodedWith, responseEncodingAccepted, withPrecompressedMediaTypeSupportMethods inherited from class org.apache.pekko.http.javadsl.server.directives.CacheConditionDirectivesconditional, conditional, conditional, conditionalMethods inherited from class org.apache.pekko.http.javadsl.server.directives.BasicDirectivescancelRejection, cancelRejections, cancelRejections, extract, extractActorSystem, extractDataBytes, extractEntity, extractExecutionContext, extractLog, extractMatchedPath, extractMaterializer, extractParserSettings, extractRequest, extractRequestContext, extractRequestEntity, extractSettings, extractStrictEntity, extractStrictEntity, extractStrictEntity, extractStrictEntity, extractUnmatchedPath, extractUri, mapInnerRoute, mapRejections, mapRequest, mapRequestContext, mapResponse, mapResponseEntity, mapResponseHeaders, mapRouteResult, mapRouteResultFuture, mapRouteResultPF, mapRouteResultWith, mapRouteResultWithPF, mapSettings, mapUnmatchedPath, pass, provide, recoverRejections, recoverRejectionsWith, toStrictEntity, toStrictEntity, toStrictEntity, toStrictEntity, withExecutionContext, withLog, withMaterializer, withSettings
- 
Constructor Details- 
PathDirectivespublic PathDirectives()
 
- 
- 
Method Details- 
ignoreTrailingSlashTries 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)
 
- 
pathMatches 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
- 
pathApplies the givenPathMatcher0to the remaining unmatched path after consuming a leading slash. The matcher has to match the remaining path completely. If matched the value extracted by thePathMatcher0is extracted on the directive level.- Parameters:
- p- (undocumented)
- inner- (undocumented)
- Returns:
- (undocumented)
 
- 
path
- 
path
- 
pathConsumes 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)
 
- 
pathEndRejects the request if the unmatchedPath of thepekko.http.javadsl.server.RequestContextis 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)
 
- 
pathEndOrSingleSlashOnly 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(org.apache.pekko.http.javadsl.model.StatusCode, java.util.function.Supplier<org.apache.pekko.http.javadsl.server.Route>)orredirectToNoTrailingSlashIfPresent(org.apache.pekko.http.javadsl.model.StatusCode, java.util.function.Supplier<org.apache.pekko.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)
 
- 
pathPrefixMatches 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
- 
pathPrefixApplies the givenPathMatcher0to 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
- 
pathPrefix
- 
pathPrefixConsumes 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)
 
- 
pathPrefixTestChecks whether the unmatchedPath of thepekko.http.javadsl.server.RequestContexthas a prefix matched by the given PathMatcher. In analogy to thepathPrefixdirective a leading slash is implied.- Parameters:
- segment- (undocumented)
- inner- (undocumented)
- Returns:
- (undocumented)
 
- 
pathPrefixTest
- 
pathPrefixTest
- 
pathPrefixTest
- 
pathSingleSlashOnly passes on the request to its inner route if the request path consists of exactly one remaining slash.- Parameters:
- inner- (undocumented)
- Returns:
- (undocumented)
 
- 
pathSuffixApplies the givenpekko.http.scaladsl.server.PathMatcherto a suffix of the remaining unmatchedPath of thepekko.http.javadsl.server.RequestContext. If matched the value extracted by thepekko.http.javadsl.server.PathMatcher0is extracted and the matched parts of the path are consumed. Note that, for efficiency reasons, the givenpekko.http.javadsl.server.PathMatcher0must 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
- 
pathSuffix
- 
pathSuffix
- 
pathSuffixTestChecks whether the unmatchedPath of thepekko.http.javadsl.server.RequestContexthas 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
- 
pathSuffixTest
- 
pathSuffixTest
- 
rawPathPrefixApplies the given matcher directly to a prefix of the unmatched path of thepekko.http.javadsl.server.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:
- segment- (undocumented)
- inner- (undocumented)
- Returns:
- (undocumented)
 
- 
rawPathPrefix
- 
rawPathPrefix
- 
rawPathPrefix
- 
rawPathPrefixTestChecks whether the unmatchedPath of thepekko.http.javadsl.server.RequestContexthas a prefix matched by the given PathMatcher. However, as opposed to thepathPrefixdirective the matched path is not actually "consumed".- Parameters:
- segment- (undocumented)
- inner- (undocumented)
- Returns:
- (undocumented)
 
- 
rawPathPrefixTest
- 
rawPathPrefixTest
- 
rawPathPrefixTest
- 
redirectToNoTrailingSlashIfPresentIf the request path ends with a slash, redirect to the same uri without trailing slash in the path.'''Caveat''': pathSingleSlash(java.util.function.Supplier<org.apache.pekko.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)
 
- 
redirectToTrailingSlashIfMissingIf 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<org.apache.pekko.http.javadsl.server.Route>)without trailing slash andpathEnd(java.util.function.Supplier<org.apache.pekko.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)
 
 
-