Difference between PUT vs. POST from a system administrator POV?

1 points by srinivasandoor ↗ HN
https://ibb.co/c3S73K6

These are what I wrote in my college notes of TCP IP that I did 6 years ago.

Much of it is confusing as both seem to be doing the same thing. Can you tell me what’s the benefit of being idempotent? As far as I know idempotent means no matter how many times you repeat a input, you get same output.

5 comments

[ 3.2 ms ] story [ 23.0 ms ] thread
POST is typically used for creating new entities - the server can determine if the entity should be created - the client might ask for an entity to be created several times

PUT is typically used for updating existing entities - the server can determine if the entity exists before updating it - imagine where a record might be tried to update twice. you would expect the same output even if the input was used twice (think poor network connection without an ACK from the server back to the client, so the client retries)

about updating twice, what if client really wanted to update twice?

I did POST with cURL in linux to send data to server, what'd have happened if I used PUT. I did it for sending FCM/GCM to android.

In the context of REST, idempotency is about duplicate requests not causing the system state to change further after the first request. For example, a POST might create a new resource each time, whereas a PUT would replace an existing resource. The POST changes the system with each call & created resource (not idempotent), whereas PUT likely wouldn't change the resource if the same content was PUT repeatedly (idempotent).

Idempotency provides resilience against messages that might be repeated (e.g., at-least-once delivery).

Idempotent operations are also typically structured as absolute, not relative data.

For example, a bank might send a message "set balance to $100", not "subtract $10 from balance" - if the message is repeated, the correct result is still obtained.

POST is usually creation, but may be any arbitrary request that needs to provide a body. PUT is replacement and PATCH is update. Functionally that means PATCH can usually update a subset of fields while PUT replaces all fields and unsets any not provided.

But it’s all up to the implementation. I regularly see them misused or everything is a POST. At then end of the day they are functionally equivalent. Idempotency is not often considered outside of specific cases like payment.