Hacker News new | past | comments | ask | show | jobs | submit login

“Toggle” is by definition not idempodent, because you get a different result each and every time. “Open” and “close” are idempodent, but not safe. The result of a GET request should always be idempodent and safe.



GET requests should have no side effects. In other words NOOP is idempotent


I'd just like to clarify that what you have described here is "safe" rather than "idempotent" [0]. Easy mistake to make, made the same mistake myself, idempotently (that is to say you only make it once ;)

Get, and NOOP, are both "safe" and naturally "idempotent" since the former encompasses the latter.

[0] https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html


GET must be safe and idempodent. In the context of http, idempodency basically means that you get the same result for each request with the same url and the same set of parameters.

Toggle should be implemented as post, since it’s neither safe, nor idempodent.


> get the same result for each request with the same url and the same set of parameters.

I think the resource can change externally...so it means that your GET request doesn't change it, but it doesn't have to be the same result every time.


No not the same result. How would the front page of any news site work then?


yes


IIRC, the rfc uses “safe” instead of “side effect free”, which is very similar, but not exactly the same.


Get should be safe, but that's not the same as indempotent. Delete requests are also indempotent as the final state will always be the same.


Reading from a database isn’t “side effect free”, neither is reading from a mutable variable.

Given that HTTP requests are supposed to trigger database reads that may return a different result after some time, then “side effect free” would indeed be incorrect.

The litmus test is ... does it always return the same output given the same input? If that can change, the it’s not describing a pure function, but a side effectful one.

And the output of a GET request can and does change.

Speaking of which people here aren’t talking of idempotency in a mathematical sense:

f(f(x)) == f(x)

If you really think about it, GET requests aren’t even idempotent ;-)


Having no side-effects means it doesn't cause side-effects, not that it can't be "victim" to them. It's no the same as purity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: