Record Class Route
- Record Components:
requestMethods
- Supported request methods. IfMethod.GET
is included,Method.HEAD
will be assumed as well. It is not necessary to includeMethod.OPTIONS
orMethod.TRACE
.pathPatterns
- Pattern(s) describing the URI paths at which aResource
is available. (Most will have only one.) See above.
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.Returns the value of thepathPatterns
record component.Returns the value of therequestMethods
record component.final String
toString()
Returns a string representation of this record class.
-
Constructor Details
-
Route
Creates an instance of aRoute
record class.- Parameters:
requestMethods
- the value for therequestMethods
record componentpathPatterns
- the value for thepathPatterns
record component
-
-
Method Details
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object)
. -
requestMethods
Returns the value of therequestMethods
record component.- Returns:
- the value of the
requestMethods
record component
-
pathPatterns
Returns the value of thepathPatterns
record component.- Returns:
- the value of the
pathPatterns
record component
-