API and Implementations
CXF 3 implements JAX-RS 2.0
Annotations
Methods are annotated and are exposed as REST services at a specified URL.
HTTP Methods
Expose your method using the @GET
, @DELETE
, @POST
or @PUT
annotation. These are the standard REST HTTP
methods.
Path Params
Path parameters are separated using slashes. e.g. if your URL is “/basket/apple”, you can annotate the method using
@GET()
@Path("/basket/{item}")
public String getFruit(@PathParam("item") String fruit) {
return "fruit is " + fruit;
}
The first @Path
annotation contains a REST Path parameter named item
. This is used as the ‘fruit’ Java
parameter. The value of this parameter will be “apple”.
The path parameter will not match slashes. Instead, you can give it a regular expression.
@GET()
@Path("/basket/{item : .+}")
public String getFruit(@PathParam("item") String fruit) {
return "fruit is " + fruit;
Now it can match URLs such as “/basket/apple/2”, and the fruit parameter will have the value of “apple/2”.