Skip to content

JAX-RS - Java Api for REST

CXF 3 implements JAX-RS 2.0

Methods are annotated and are exposed as REST services at a specified URL.

Expose your method using the @GET, @DELETE, @POST or @PUT annotation. These are the standard REST HTTP methods.

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”.