43.2. Basic JAX-RS annotations
- the URI of the service's resources
- how the class' methods are mapped to the HTTP verbs
Setting the path
@Pathannotation specifies the URI of a resource. The annotation is defined by the
javax.ws.rs.Pathinterface and it can be used to decorate either a resource class or a resource method. It takes a string value as its only parameter. The string value is a URI template that specifies the location of an implemented resource.
- unprocessed path components
- parameter identifiers surrounded by
}NoteParameter identifiers can include regular expressions to alter the default path processing.
Example 43.2. URI template syntax
colorparameter is assigned to blue. The value of the
numberparameter is assigned 12.
@Pathannotation is decorating. If it is placed on a root resource class, the URI template is the root URI of all resources in the tree and it is appended directly to the URI at which the service is published. If the annotation decorates a sub-resource, it is relative to the root resource URI.
Specifying HTTP verbs
javax.ws.rs.DELETEspecifies that the method maps to a
javax.ws.rs.GETspecifies that the method maps to a
javax.ws.rs.POSTspecifies that the method maps to a
javax.ws.rs.PUTspecifies that the method maps to a
javax.ws.rs.HEADspecifies that the method maps to a
POST. Mapping it to a
DELETEwould result in unpredictable behavior.