Record Class Route

java.lang.Object
java.lang.Record
is.galia.resource.Route
Record Components:
requestMethods - Supported request methods. If Method.GET is included, Method.HEAD will be assumed as well. It is not necessary to include Method.OPTIONS or Method.TRACE.
pathPatterns - Pattern(s) describing the URI paths at which a Resource is available. (Most will have only one.) See above.

public record Route(Set<Method> requestMethods, Set<Pattern> pathPatterns) extends Record

Maps one or more HTTP methods and a URI path regex/pattern to a Resource.

Notes on path pattern implementation

Patterns should match only whole paths recognized by a single resource and no others. Matching whole paths can be accomplished using start and end anchors (^ and $). Otherwise, it is possible for a client to supply a longer path that will still match.

Patterns should not conflict with the ones used by built-in resources. The built-in patterns are not centrally documented, but built-in resources are matched before plugin resources, so if you find that a built-in resource is handling the requests that your plugin should be, you should reconsider your pattern.

An unmatched path will cause an HTTP 404 response.

You must decide how strict to make the regex. For example, if your resource supports /path/red and /path/orange, but not /path/blue, do you want /path/blue to return a generic HTTP 404 response, or do you want to make the color part of the path dynamic (see below), and check it in your Resource implementation, in order to return your own custom response?

A pattern must consider the path extension, if supported, as this is part of the path. It must not consider the query nor any other part of the URL.

Dynamic path segments

Dynamic path segments are supported using regex groups. The matches will be made available via Request.getPathArguments().

Example

The following pattern matches a resource at /my-resource/:identifier, and makes the identifier portion available as a path argument:

^/my-resource/([^/]+)$

This translates to: "Match a path that starts with /my-resource and ends with a dynamic path segment at least one character long that does not include a slash."

  • Constructor Details

    • Route

      public Route(Set<Method> requestMethods, Set<Pattern> pathPatterns)
      Creates an instance of a Route record class.
      Parameters:
      requestMethods - the value for the requestMethods record component
      pathPatterns - the value for the pathPatterns record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • requestMethods

      public Set<Method> requestMethods()
      Returns the value of the requestMethods record component.
      Returns:
      the value of the requestMethods record component
    • pathPatterns

      public Set<Pattern> pathPatterns()
      Returns the value of the pathPatterns record component.
      Returns:
      the value of the pathPatterns record component