Monday, March 9, 2009

Support for REST in Spring 3.0

Arjen Poutsma of SpringSource introduces REST in Spring 3.0.

The short article outlines how Spring @MVC framework is augmented in release 3.0 to handle incoming RESTful requests.

At the core of RESTful support are URI templates:
A URI template is a URI-like string, containing one or more variable names. When these variables are substituted for values, the template becomes a URI.
The templates are handled by @PathVariable annotation(s). Here's a code snippet illustrating the concept:
@RequestMapping("/hotels/{hotelId}")
public String getHotel(@PathVariable hotelId, Model model) {
List hotels = hotelService.getHotels();
model.addAttribute("hotels", hotels);
return "hotels";
}
The support of REST-style requests seems to be very intuitive and blends naturally into the @MVC paradigm.

0 comments: