Simple REST with CRUD



@Path("Item")
public class ItemRestService {

@GET
@Produces(MediaType.APPLICATION_XML)
public Items getItemss() {
/* code to retrieve and return list of Items */
}
 
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response createItem(Item item) {
/* code to store item in db and build and return appropriate response */
return response;
}

@DELETE
@Path("{id}")
public Response deleteItem(@PathParam("id") Long itemId) {
/* code to delete requested id item from database 
                   and return appropriate response */
return response;
}
}

This simple REST service that can consume and produce an XML representation of
a Item. The getItems() method retrieves the list of Items from the database and returns an XML representation (using content negotiation) of this list, accessible through a GET method. The createItem() method takes an XML representation of a Item and persists it to the database. This method is invoked with an HTTP POST and returns a Response with the URI (itemUri) of the new Item as well as the created status. The deleteItem method takes a Item id as a parameter and deletes it from the database.


Ref: Beginning JavaEE 7