View RSS Feed

Spring Framework

RESTful PUT Method in Spring

Rate this Entry
by , 11-28-2011 at 01:56 AM (3177 Views)
In my previous tip, I looked at the verbs available for RESTful services. In this tip, I will show you how to write RESTful methods using the verb HTTP Verb, PUT.

The purpose of the PUT methodís is exactly as it states. Is serves to transfer the resourceís state from the client to the server. For an example of this, please see the following method that Iíve created for putCar() that is annotated to receive a Car object from a PUT request:

Java Code:
@RequestMapping(value="/{id}", method=RequestMethod.PUT) 
public void putCar(@PathVariable("id") long id,
	@Valid Car car) { 
The putCar() method is annotated with @RequestMapping. The @RequestMapping annotation is very simlar to the getCar() method that I created in the RESTful controller. As PUT is the semantic opposite to GET, it makes sense that they would be similar. The only real difference is in the method attribute (i.e. HTTP PUT vs. GET requests). Finally the @ResponseStatus will provide back the HTTP status that will be returned with the response of the client. In the next post, I will do the same with DELETE.

Submit "RESTful PUT Method in Spring" to Facebook Submit "RESTful PUT Method in Spring" to Digg Submit "RESTful PUT Method in Spring" to Submit "RESTful PUT Method in Spring" to StumbleUpon Submit "RESTful PUT Method in Spring" to Google

Updated 11-30-2011 at 02:39 PM by Spring Framework