Java Reference
In-Depth Information
@Path ( " { id } ")
public String getCustomer(@PathParam(" id " ) int
int id ) {
...
}
}
These template parameters can be embedded anywhere within an @Path declaration. For ex-
ample:
@Path ( "/" )
public
public class
class CustomerResource
CustomerResource {
@GET
@Path ( " customers / { firstname }-{ lastname } ")
public String getCustomer(@PathParam(" firstname ") String first,
@PathParam(" lastname " ) String last ) {
...
}
}
In our example, the URI is constructed with a customer's first name, followed by a hyphen,
ending with the customer's last name. So, the request GET /customers/333 would no longer
match to getCustomer() , but a GET/customers/bill-burke request would.
Regular expressions
@Path expressions are not limited to simple wildcard matching expressions. For example,
our getCustomer() method takes an integer parameter. We can change our @Path value to
match only digits:
@Path ( "/customers" )
public
public class
class CustomerResource
CustomerResource {
@GET
@Path ( " { id : \\ d +} ")
public String getCustomer(@PathParam(" id " ) int
int id ) {
...
}
}
Regular expressions are not limited in matching one segment of a URI. For example:
@Path ( "/customers" )
public
public class
class CustomerResource
CustomerResource {
@GET
@Path ( " { id : .+} ")
Search WWH ::




Custom Search