Class RequestPathParams

All Implemented Interfaces:
Serializable, Cloneable, Iterable<RequestPathParam>, Collection<RequestPathParam>, List<RequestPathParam>, RandomAccess

Represents the path parameters in an HTTP request.

The RequestPathParams object is the API for accessing the matched variables and remainder on the URL path.

@RestPost(...) public Object myMethod(RequestPathParams path) {...}

Example:

@RestPost(..., path="/{foo}/{bar}/{baz}/*") public void doGet(RequestPathParams path) { // Example URL: /123/qux/true/quux int foo = path.get("foo").asInteger().orElse(0); // =123 String bar = path.get("bar").orElse(null); // =qux boolean baz = path.get("baz").asBoolean().orElse(false); // =true String remainder = path.getRemainder(); // =quux }

Some important methods on this class are:

See Also:
See Also:
  • Constructor Details

    • RequestPathParams

      public RequestPathParams(RestSession session, RestRequest req, boolean caseSensitive)
      Constructor.
      Parameters:
      session - The current HTTP request session.
      req - The current HTTP request.
      caseSensitive - Whether case-sensitive name matching is enabled.
  • Method Details

    • parser

      Sets the parser to use for part values.
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • caseSensitive

      public RequestPathParams caseSensitive(boolean value)
      Sets case sensitivity for names in this list.
      Parameters:
      value - The new value for this setting.
      Returns:
      This object (for method chaining).
    • addDefault

      Adds default entries to these parameters.

      Similar to set(String, Object) but doesn't override existing values.

      Parameters:
      pairs - The default entries.
      Can be null.
      Returns:
      This object.
    • addDefault

      Adds default entries to these parameters.

      Similar to set(String, Object) but doesn't override existing values.

      Parameters:
      pairs - The default entries.
      Can be null.
      Returns:
      This object.
    • addDefault

      public RequestPathParams addDefault(String name, String value)
      Adds a default entry to the query parameters.
      Parameters:
      name - The name.
      value - The value.
      Returns:
      This object.
    • add

      public RequestPathParams add(String name, Object value)
      Adds a parameter value.

      Parameter is added to the end.
      Existing parameter with the same name are not changed.

      Parameters:
      name - The parameter name. Must not be null.
      value - The parameter value.
      Returns:
      This object.
    • add

      public RequestPathParams add(NameValuePair... parameters)
      Adds request parameter values.

      Parameters are added to the end.
      Existing parameters with the same name are not changed.

      Parameters:
      parameters - The parameter objects. Must not be null.
      Returns:
      This object.
    • set

      public RequestPathParams set(String name, Object value)
      Sets a parameter value.

      Parameter is added to the end.
      Any previous parameters with the same name are removed.

      Parameters:
      name - The parameter name. Must not be null.
      value - The parameter value.
      Converted to a string using Object.toString().
      Can be null.
      Returns:
      This object.
    • set

      public RequestPathParams set(NameValuePair... parameters)
      Sets request header values.

      Parameters are added to the end of the headers.
      Any previous parameters with the same name are removed.

      Parameters:
      parameters - The parameters to set. Must not be null or contain null.
      Returns:
      This object.
    • remove

      Remove parameters.
      Parameters:
      name - The parameter name. Must not be null.
      Returns:
      This object.
    • subset

      public RequestPathParams subset(String... names)
      Returns a copy of this object but only with the specified param names copied.
      Parameters:
      names - The list to include in the copy.
      Returns:
      A new list object.
    • contains

      public boolean contains(String name)
      Returns true if the parameters with the specified name is present.
      Parameters:
      name - The parameter name. Must not be null.
      Returns:
      true if the parameters with the specified name is present.
    • containsAny

      public boolean containsAny(String... names)
      Returns true if the parameter with any of the specified names are present.
      Parameters:
      names - The parameter names. Must not be null.
      Returns:
      true if the parameter with any of the specified names are present.
    • getAll

      Returns all the parameters with the specified name.
      Parameters:
      name - The parameter name.
      Returns:
      The list of all parameters with the specified name, or an empty list if none are found.
    • stream

      Returns all headers with the specified name.
      Parameters:
      name - The header name.
      Returns:
      The stream of all headers with matching names. Never null.
    • getSorted

      Returns all headers in sorted order.
      Returns:
      The stream of all headers in sorted order.
    • getNames

      public List<String> getNames()
      Returns all the unique header names in this list.
      Returns:
      The list of all unique header names in this list.
    • getFirst

      Returns the first parameter with the specified name.

      Note that this method never returns null and that RequestHttpPart.isPresent() can be used to test for the existence of the parameter.

      Parameters:
      name - The parameter name.
      Returns:
      The parameter. Never null.
    • getLast

      Returns the last parameter with the specified name.

      Note that this method never returns null and that RequestHttpPart.isPresent() can be used to test for the existence of the parameter.

      Parameters:
      name - The parameter name.
      Returns:
      The parameter. Never null.
    • get

      public RequestPathParam get(String name)
      Returns the last parameter with the specified name.

      This is equivalent to getLast(String).

      Parameters:
      name - The parameter name.
      Returns:
      The parameter value, or Optional.empty() if it doesn't exist.
    • get

      public <T> Optional<T> get(Class<T> type)
      Returns the path parameter as the specified bean type.

      Type must have a name specified via the Path annotation and a public constructor that takes in either value or name,value as strings.

      Type Parameters:
      T - The bean type to create.
      Parameters:
      type - The bean type to create.
      Returns:
      The bean, never null.
    • copy

      Makes a copy of these parameters.
      Returns:
      A new parameters object.
    • getRemainder

      Returns the decoded remainder of the URL following any path pattern matches.

      The behavior of path remainder is shown below given the path pattern "/foo/*":

      URL Path Remainder
      /foo null
      /foo/ ""
      /foo// "/"
      /foo/// "//"
      /foo/a/b "a/b"
      /foo//a/b/ "/a/b/"
      /foo/a%2Fb "a/b"
      Example:

      // REST method @RestGet("/foo/{bar}/*") public String doGetById(RequestPathParams path, int bar) { return path.remainder().orElse(null); }

      The remainder can also be retrieved by calling get("/**").

      Returns:
      The path remainder string.
    • getRemainderUndecoded

      Same as getRemainder() but doesn't decode characters.

      The undecoded remainder can also be retrieved by calling get("/*").

      Returns:
      The un-decoded path remainder.
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<RequestPathParam>