-1

i'm new in rest and confuse about http methods like get,post,put,delete,option,head can any one please share me simple example.

here is my example:

@GET 
    @Produces("text/plain")
    public String getIt() {
        return "Hi there!";
    }

    @DELETE
    @Produces("text/plain")
    @Path("/getItDelTest")
    public String getItDelTest()
    {
        return "Hi there is getITDelTest method";
    }

    @HEAD
    @Produces("text/plain")
    @Path("/getItHeadTest")
    public String getItHeadTest()
    {
        return "Hi there is getITHeadTest method";
    }

    @PUT
    @Produces("text/plain")
    @Path("/getItPutTest")
    public String getItPutTest()
    {
        return "Hi there is getITPutTest method";
    }


    @POST
    @Produces("text/plain")
    @Path("/getItPost")
    public String getItPost()
    {
        return "Hi there is getItPost method";
    }

above this example i'm just create a simple method with diffrent-2 nature but i don't understand why we need all that if we able to do all these action with post

Nikesh Pathak
  • 450
  • 2
  • 7
  • 18
  • i think here is the ans that i exactly want [link](http://www.prideparrot.com/blog/archive/2011/10/using_http_methods_in_rest) – Nikesh Pathak Apr 21 '14 at 10:22

2 Answers2

6

The GET method is meant for data retrieval only and should not have any side-effects. But POST is meant for that specific purpose: altering data on the server side.

To change the state of a resource or to update it, use PUT and To remove or delete a resource, use DELETE..

Please read : https://www.ibm.com/developerworks/webservices/library/ws-restful/

Shreyos Adikari
  • 12,348
  • 19
  • 73
  • 82
0

The difference is based on the HTTP Action verb. This verb is contained within the actual HTTP message. The handling of these verbs is implementation specific. For example in C# I can have 2 Web API methods named Hello in the same controller. One could be mapped to the GET and the other to the PUT or DELETE etc....

T McKeown
  • 12,971
  • 1
  • 25
  • 32