Learn to use JAX-RS @Path annotation and write resource path in it for URI matching. Paths can be written in simple form (static or path parameter) or complex form (regex based).
1. JAX-RS @Path URI Matching Types
JAX-RS @Path
annotation is used to specify the URI on which the resources will be accessible to other applications or clients. The @javax.ws.rs.Path annotation must exist on either the class and/or a resource method. If it exists on both the class and method, the relative path to the resource method is a concatenation of the class and method.
URIs in @Path are defined in two ways.
- Simple URI matching
- Regex based URI matching
2. JAX-RS @Path – Simple URI matching
In simplest form, URI consist of static path and if needed some per-defined parameters.
@Path ("users")
– matches to application/user-management/users.@Path ("users/{id}")
– matches to application/user-management/users/12.
3. JAX-RS @Path – Regex based URI matching
In complex form, we can use regular expression based parameter matching.
@Path("/users/{id: [0-9]*}")
(support digit only) – matches to http://localhost:8080/RESTfulDemoApplication/user-management/users/123456.@Path("/users/{id: [a-zA-Z][a-zA-Z_0-9]}")
(first character alphabet and then alpha-numerics) – matches to http://localhost:8080/RESTfulDemoApplication/user-management/users/abc123.
Happy Learning !!
Leave a Reply