Java Reference
In-Depth Information
TABLE 10-1. Advanced JAX-RS Annotations
Extracting Path Parameters
URI path templates are URIs with variables embedded within the URI syntax. The
@PathParam
annotation lets you use variable URI path fragments when you call a meth-
od.
The following code snippet shows how to extract the last name of an employee when the
employee's email address is provided:
@Path(/employees/"{firstname}.{lastname}@{domain}.com")
public class EmpResource {
@GET
@Produces("text/xml")
public String getEmployeelastname(@PathParam("lastname") String
lastName) {
...
}
}
In this example, the
@Path
annotation defines the URI variables (or path parameters)
{firstname}
,
{lastname}
, and
{domain}
. The
@PathParam
in the method
parameter of the request method extracts the last name from the email address.
If your HTTP request is GET
/employees/john.doe@example.com
, the value
“
doe
” is injected into
{lastname}
.