Class RouteBuilder

java.lang.Object
com.linecorp.armeria.server.RouteBuilder

public final class RouteBuilder
extends Object
Builds a new Route.
  • Method Details

    • path

      public RouteBuilder path​(String pathPattern)
      Sets the Route to match the specified pathPattern. e.g.
      • /login (no path parameters)
      • /users/{userId} (curly-brace style)
      • /list/:productType/by/:ordering (colon style)
      • exact:/foo/bar (exact match)
      • prefix:/files (prefix match)
      • glob:/~*/downloads/** (glob pattern)
      • regex:^/files/(?<filePath>.*)$ (regular expression)
      Throws:
      IllegalArgumentException - if the specified path pattern is invalid
    • path

      public RouteBuilder path​(String prefix, String pathPattern)
      Sets the Route to match the specified prefix and pathPattern. The mapped HttpService is found when a path is under the specified prefix and the rest of the path matches the specified pathPattern.
      See Also:
      path(String)
    • exact

      public RouteBuilder exact​(String exactPath)
      Sets the Route to match the specified exact path.
    • pathPrefix

      public RouteBuilder pathPrefix​(String prefix)
      Sets the Route to match when a path is under the specified prefix. It also removes the specified prefix from the matched path so that mappedPath does not have the specified prefix. For example, when prefix is "/foo/":
      • "/foo/" translates to "/"
      • "/foo/bar" translates to "/bar"
      • "/foo/bar/baz" translates to "/bar/baz"
      This method is a shortcut to pathPrefix(prefix, true).
    • pathPrefix

      public RouteBuilder pathPrefix​(String prefix, boolean stripPrefix)
      Sets the Route to match when a path is under the specified prefix. When stripPrefix is true, it also removes the specified prefix from the matched path so that mappedPath does not have the specified prefix. For example, when prefix is "/foo/":
      • "/foo/" translates to "/"
      • "/foo/bar" translates to "/bar"
      • "/foo/bar/baz" translates to "/bar/baz"
    • catchAll

      public RouteBuilder catchAll()
      Sets the Route to match any path.
    • glob

      public RouteBuilder glob​(String glob)
      Sets the Route to match the specified glob. "*" in the expression matches a path component non-recursively whereas "**" matches path components recursively.
    • regex

      public RouteBuilder regex​(String regex)
      Sets the Route to match the specified regex. It also extracts the values of the named groups to pathParams: e.g. "^/users/(?<userId>[0-9]+)$" will extract the second numeric part of the path into the "userId" path parameter.
    • regex

      public RouteBuilder regex​(Pattern regex)
      Sets the Route to match the specified regex. It also extracts the values of the named groups to pathParams: e.g. "^/users/(?<userId>[0-9]+)$" will extract the second numeric part of the path into the "userId" path parameter.
    • methods

      public RouteBuilder methods​(HttpMethod... methods)
      Sets the Route to support the specified HttpMethods. If not set, the mapped HttpService accepts any HttpMethods.
    • methods

      public RouteBuilder methods​(Iterable<HttpMethod> methods)
      Sets the Route to support the specified HttpMethods. If not set, the mapped HttpService accepts any HttpMethods.
    • consumes

      public RouteBuilder consumes​(MediaType... consumeTypes)
      Sets the Route to consume the specified MediaTypes. If not set, the mapped HttpService accepts HttpRequests that have any HttpHeaderNames.CONTENT_TYPE. In order to get this work, methods(Iterable) must be set.
    • consumes

      public RouteBuilder consumes​(Iterable<MediaType> consumeTypes)
      Sets the Route to consume the specified MediaTypes. If not set, the mapped HttpService accepts HttpRequests that have any HttpHeaderNames.CONTENT_TYPE. In order to get this work, methods(Iterable) must be set.
    • produces

      public RouteBuilder produces​(MediaType... produceTypes)
      Sets the Route to produce the specified MediaTypes. If not set, the mapped HttpService accepts HttpRequests that have any HttpHeaderNames.ACCEPT. In order to get this work, methods(Iterable) must be set.
    • produces

      public RouteBuilder produces​(Iterable<MediaType> produceTypes)
      Sets the Route to produce the specified MediaTypes. If not set, the mapped HttpService accepts HttpRequests that have any HttpHeaderNames.ACCEPT. In order to get this work, methods(Iterable) must be set.
    • matchesParams

      public RouteBuilder matchesParams​(String... paramPredicates)
      Sets the Route to accept a request if it matches all the specified predicates for HTTP parameters. The predicate can be one of the following forms:
      • some-param=some-value which means that the request must have a some-param=some-value parameter
      • some-param!=some-value which means that the request must not have a some-param=some-value parameter
      • some-param which means that the request must contain a some-param parameter
      • !some-param which means that the request must not contain a some-param parameter

      Note that these predicates can be evaluated only with the query string of the request URI. Also note that each predicate will be evaluated with the decoded value of HTTP parameters, so do not use percent-encoded value in the predicate.

      See Also:
      MatchesParam
    • matchesParams

      public RouteBuilder matchesParams​(Iterable<String> paramPredicates)
      Sets the Route to accept a request if it matches all the specified predicates for HTTP parameters. The predicate can be one of the following forms:
      • some-param=some-value which means that the request must have a some-param=some-value parameter
      • some-param!=some-value which means that the request must not have a some-param=some-value parameter
      • some-param which means that the request must contain a some-param parameter
      • !some-param which means that the request must not contain a some-param parameter

      Note that these predicates can be evaluated only with the query string of the request URI. Also note that each predicate will be evaluated with the decoded value of HTTP parameters, so do not use percent-encoded value in the predicate.

      See Also:
      MatchesParam
    • matchesParams

      public RouteBuilder matchesParams​(String paramName, Predicate<? super String> valuePredicate)
      Sets the Route to accept a request when the specified valuePredicate evaluates true with the value of the specified paramName parameter.
    • matchesHeaders

      public RouteBuilder matchesHeaders​(String... headerPredicates)
      Sets the Route to accept a request if it matches all the specified predicates for HttpHeaders. The predicate can be one of the following forms:
      • some-header=some-value which means that the request must have a some-header: some-value header
      • some-header!=some-value which means that the request must not have a some-header: some-value header
      • some-header which means that the request must contain a some-header header
      • !some-header which means that the request must not contain a some-header header
      See Also:
      MatchesHeader
    • matchesHeaders

      public RouteBuilder matchesHeaders​(Iterable<String> headerPredicates)
      Sets the Route to accept a request if it matches all the specified predicates for HttpHeaders. The predicate can be one of the following forms:
      • some-header=some-value which means that the request must have a some-header: some-value header
      • some-header!=some-value which means that the request must not have a some-header: some-value an header
      • some-header which means that the request must contain a some-header header
      • !some-header which means that the request must not contain a some-header header
      See Also:
      MatchesHeader
    • matchesHeaders

      public RouteBuilder matchesHeaders​(CharSequence headerName, Predicate<? super String> valuePredicate)
      Sets the Route to accept a request when the specified valuePredicate evaluates true with the value of the specified headerName header.
    • build

      public Route build()
      Returns a newly-created Route based on the properties of this builder.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals​(@Nullable Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object