concept restful web service in category camel
appears as: RESTful web services, RESTful web service

This is an excerpt from Manning's book Camel in Action.
For over a decade, web services have played an important role in integrating loose and disparate systems together. As a natural evolution of humankind and the IT industry, we learn and get smarter. Recently, RESTful web services (a.k.a. REST services) have taken over as the first choice for integrating services. This chapter covers a lot of ground about developing and using RESTful web services with Camel.
Listing 10.1 JAX-RS implementation of the Rider Auto Parts REST service
import javax.ws.rs.DELETE; #1 import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; @Path("/orders/") #2 @Produces("application/xml") public class RestOrderService { private OrderService orderService; public void setOrderService(OrderService orderService) { #3 this.orderService = orderService; } @GET @Path("/{id}") public Response getOrder(@PathParam("id") int orderId) { #4 Order order = orderService.getOrder(orderId); if (order != null) { return Response.ok(order).build(); #5 } else { return Response.status(Response.Status.NOT_FOUND).build(); } } @PUT public Response updateOrder(Order order) { #6 orderService.updateOrder(order); return Response.ok().build(); } @POST public Response createOrder(Order order) { #7 String id = orderService.createOrder(order); return Response.ok(id).build(); } @DELETE @Path("/{id}") public Response cancelOrder(@PathParam("id") int orderId) { #8 orderService.cancelOrder(orderId); return Response.ok().build(); } } #1 Java imports the JAX-RS annotations #2 Defines the entry path of the RESTful web service #3 To inject the OrderService implementation #4 GET order by ID #5 The Response builder to return the order model in the response #6 PUT to update an existing order #7 POST to create a new order #8 DELETE to cancel an existing order