Path Variables
The path can contain variables that get resolved to @Path parameters or access through the RestRequest.getPathParams() method.
Example
@Rest(
path="/myResource/{foo}/{bar}"
)
public class MyResource extends BasicRestServlet {
@RestPost("/{baz}")
public void String doX(@Path String foo, @Path int bar) {
...
}
}
Variables can be used on either top-level or child resources and can be defined on multiple levels.
Path variables resolved in parent resource paths are also available to the child resources.
note
All variables in the path must be specified or else the target will not resolve and a 404 will result.
Path Remainder
The path remainder (the part matched by /*) can be captured using either @Path("/*") or the more intuitive @PathRemainder annotation.
Example
@Rest
public class MyResource extends BasicRestServlet {
// Using @PathRemainder (preferred)
@RestGet("/files/*")
public File getFile(@PathRemainder String path) {
return new File(path);
}
// Equivalent using @Path("/*")
@RestPost("/upload/*")
public void uploadFile(@Path("/*") String path, @Content File file) {
...
}
}
The @PathRemainder annotation supports the same features as @Path, including:
- Default values via
def()property - Custom parsers and serializers
- Schema validation
- OpenAPI/Swagger documentation generation
Share feedback or follow-up questions for this page directly through GitHub.