Difference between Get and post method in comparision with HTTP and REST
Asked Answered
H

2

8

I am new to REST. I want to know when to use get methods and when to use post methods. In the process of my literature survey I came across this knowledge.

Actually when I searched for HTTP get and post methods, I read that get doesnt encode URL and post encodes the URL

When I searched for rest get and post methods, I read that get method is used to retrieve data from server and post method is to add some data to server.

But I also read that rest is nothing but a convention to use HTTP.

So I feel like some things are contradicting here. Are the methods of HTTP different?

Please clarify. Also any suggestions on when to use get and post methods are welcome

Resource from which i got this information:

https://www.ibm.com/developerworks/webservices/library/ws-ful/

http://www.cs.tut.fi/~jkorpela/forms/methods.html

Hollishollister answered 27/6, 2012 at 15:0 Comment(1)
Can GET and POST be used on the same method?Chain
F
11

GET should be used to retrieve a resource. This operation should be idempotent, meaning it should not change any state on the server.

POST should be used to add new information to the server. This is usually performed on a URL that represents a "container" of resources. The POST will add a new resource to this container.

PUT should be used to update an existing resource.

DELETE should be obvious.

You might enjoy reading this: http://tomayko.com/writings/rest-to-my-wife

Floreneflorentia answered 27/6, 2012 at 15:18 Comment(6)
Nitpicking: “idempotent” doesn’t mean “does not change state”. DELETE changes state, but it is idempotent. “Does not change state” is properly referred to as “without side-effects”.Anasarca
From Wikipedia: Idempotence is the property of certain operations in mathematics and computer science, that they can be applied multiple times without changing the result beyond the initial application. [END QUOTE]. By this definition, a DELETE would fail when executed the second time.Floreneflorentia
Can we use GET and POST on the same method?Chain
Not sure what you're asking. Can you write a method that does the same thing regardless of whether the request is a GET or a POST? Yes, but it doesn't really follow normal REST conventions.Floreneflorentia
How I explained REST to my wife, working link: looah.com/source/view/2284Sundaysundberg
I think POST is used to update an existing resource, whereas PUT is used to add a new resource. Correct me if I am wrong.Servitor
C
0

The portion of your question which has not received any attention as of yet, and which is probably causing some of your confusion, is: "REST is nothing but a convention to use HTTP." Which is an inaccurate way of describing what REST is/does in terms of it using HTTP to manipulate the state of an app. This is officially known as HATEOAS - http://en.wikipedia.org/wiki/HATEOAS and is pretty much the heart of RESTful web services concept.

Cordelier answered 27/6, 2012 at 19:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.