HTTP Methods in RESTful world

3
1311
Learn on Udemy Today!

It would be great if we know some of the basic information on HTTP methods before we implement any RESTful webservices. This will help us to design better Web API in real time. Read further to know about what is HTTP methods and how each HTTP methods are attached in RESTful Java context.

HTTP defines methods (sometimes referred to as verbs) to indicate the desired action to be performed on the identified resource – wiki

Mostly used HTTP methods:

HTTP Methods Explanation
GET GET method is used to retrieve any information from the given request URI. We can use GET method to fetch single or multiple entity information from the given URI.

When to use:

GET is often used to fetch list of objects or find an object by identifier

For example,

/books (multiple objects)

/books/{id} (Finds an object from the given {id})

PUT PUT method is similar to POST method.
POST POST method is normally used to create or update an entity under the given URI. Sometimes this method will be interchanged with PUT

When to use:

POST method is used to create a new object or update the existing object from the given payload in the request body

DELETE DELETE method is used to delete an entity under the given request URI.

For example,

DELETE   /books (Delete multiple objects)

DELETE   /books/{id} (Delete an object based on the given {id})

HEAD HEAD method is similar to GET except that, the server will NOT return a message body in the response. The meta information of HEAD response is identical to the response of GET method.

When to use:

HEAD is often used to check the resource availability and connectivity by reducing the response payload

 

HTTP methods in RESTful Java world:

Please go through the detailed list of annotations on how each HTTP methods is being handled in RESTful Java world.

HTTP Methods RESTful Java annotations
GET @GET
PUT @PUT
POST @POST
DELETE @DELETE
HEAD @HEAD

 

Ignore the other methods like TRACE, OPTIONS, CONNECT and PATCH for the moment. Keep watching this space for implementation details in the coming days!

Please share this if you liked the article and also post your valuable comments for improvements!

SHARE
Previous articleCodegeist: Atlassian hackathon for developers
Next articleBluemixathon: An IBM hackathon for developers
Thamizharasu is a Java developer living in India. He is writing about Java programming, RESTful web services and frameworks. He also loves working with Web API, Elastic search and Firebase. Currently he is a Madras JUG lead and you can follow him on Twitter @zarub2k