4 ms·
What Is the Difference Between Get vs. Post vs. Put? Mainly Post vs. Put?
First of all I am not learning this currently from web development Point of view. So I think I don’t need the extreme level of understanding. I am studying this in a topic called “HTTP protocol”. And in my opinion, I need to learn enough to write what it does in exam paper.
It is so confusing in internet. I can’t explain enough. Firstly I was just confused between PUT and POST. But later someone started to tell me that you could use GET instead of these two in submitting form. That got me confused to next level.
What I have already understood(be it wrong or right I am not sure).
GET-: It helps to retrieve the file indicated by URL in request line from server.
PUT and POST seems same thing to me.
PUT places data in body to the URL in request line.
POST has no such definitions anywhere in books or internet. And it is generalized as “POST is used to submit form data”.
But the gist of these two seems similar ie post data to server. What’s the difference?
And there are like 6,670,000,000 results in google.
But I don’t know how stupid I am to not get this.Most articles in internet are copied from each other and written pretty unprofessionally. I am not very smart. I mean smart in the sense that one who can understand anything taught by anyone and doesn’t need that clarity. I need something very simplified to understand and I don’t find it at least till now.
https://stackoverflow.com/questions/630453/what-is-the-difference-between-post-and-put-in-http
https://stackoverflow.com/questions/107390/whats-the-difference-between-a-post-and-a-put-http-request
These are perhaps the only reputable answers about this but I find them very confusing.
They say idemptotencyy is there in some and not in other. But I want their basic difference in working.(PUT is idempotent).
Idempotent means you can keep repeating the same thing again and again but the final result will be the same as the initial result that happened when you did that thing for the first time.
Is this the only difference between POST and PUT working and is their definition same?
Another thing that I am seeing is PUT keeps data to be sent in URL whereas POST doesn’t do it. How do we know about it? I can’t see any information that shows this thing practically. (They say while googling you use PUT so that you can visit that page again as well.) But IDK how to explain, I don’t know how.
Just tell me the difference between PUT and POST in terms of real working difference, Like how they work. Thanks for the information.
- efortis 4y agoPOST vs. PUT is convention. Independent of the HTTP protocol, the actual server-side application logic is what matters. Example 1: you can code a request handler for a PUT that doesn't behave idempotently, and a POST that does. Example 2: you can code a handler that creates non-existing records with either a PUT or POST. It'll be confusing (especially Ex.2), but it's doable. --- PUT and POST have request bodies. And as GET requests, they can send data in the URI (in the query string). But the convention is not to do that in PUT and POST requests. But unconventionally, you can implement app logic to consume the query string data in a PUT or POST. Furthermore, you can include a body in a GET request, maybe a Web-Application Firewall rejects the request, but HTTP-wise you can send it, although it'll be unconventional. --- In other words, consider the HTTP (v1.1) message format: <REQUEST LINE> (e.g. POST /add-user HTTP/1.1) <HEADERS> (e.g. Host: http://example.com) <BODY> {"name":"John"} * "POST" or "PUT" the difference is just that string. * /add-user could also have a qs -> /add-user?foo=bar * Think of the <BODY> as optional (it goes after the <HEADERS> and two newlines). --- Good luck in your exam.
- e1g 4y agoThe HTTP spec is the authoritative source, and it’s pleasantly well-written and approachable. Set aside 10 minutes to read a few pages from this paragraph and you’ll understand this distinction better than most in the industry https://datatracker.ietf.org/doc/html/rfc7231#section-4.2 https://datatracker.ietf.org/doc/html/rfc7231#section-4.2
- landa 4y agoIt's more about convention. Typically, PUT overwrites data, whereas POST adds data. If you PUT to /users/3 you overwrite a user, whereas if you POST to /users you add a user.