Key REST Verbs
by, 11-28-2011 at 01:54 AM (2252 Views)
In my previous tip, I looked at setting up RESTful Controllers. Now in the post we will look at the verbs available for RESTful services. . Although this is nice for writing RESTless controllers, it is not ideal for writing RESTful controllers. The reason is that controllers made in this way are action oriented and not resource oriented. This can be easily surmised by the names used for the different requests which are focused on the particular use cases but not on the resources.
One of the really nice things about RESTful services is that there is only need a handful of verbs to be able to act upon those resources. They are the basic verbs to transfer the state of a resource. This means that for any given resource, the most common operations will be to create a resource on the server, retrieve it from the server, update it on the server, or delete it from the server.
Most individuals might be current with the most widely used verbs (post, get, put, and delete ) corresponding to the four most widely used methods as defined by the HTTP specification. They are shown in the table below:
Note that the HTTP methods are characterized by their safety (i.e if it doesnít change a resource) and idempotency (i.e. repeated requests should not alter the resource after the first request). By definition, all safe methods are also idempotent, but not all idempotent methods are safe.
Spring supports all HTTP methodís so you should not have any problems creating RESTful clients. Please donít forget that just because Spring supports all HTTP methods doesnít mean that you can use them irresponsibly. You can seriously damage your application if you donít use them properly. In the next tip, I will show you how to use some of the less popular HTTP methods.