REST Saving GET history
Reading about REST protocol I have seen that GET calls should not update the server / should be idempotent, so I thought: what if I want the user searches (made by a GET call) to be saved? My conclusion was that since it's an idempotent operation (first and N save have the same effect on server) it's ok in that case that a GET call modifies server data.
Am I right?
Thanks作者: Lucas Janon 的来源 发布者： 2017 年 12 月 27 日
what if I want the user searches (made by a GET call) to be saved?
Sure, go right ahead.
My conclusion was that since it's an idempotent operation (first and N save have the same effect on server) it's ok in that case that a GET call modifies server data.
Your conclusion is good, your reasoning is a bit soft.
Roy Fielding, writing in 2002
HTTP does not attempt to require the results of a GET to be safe. What it does is require that the semantics of the operation be safe, and therefore it is a fault of the implementation, not the interface or the user of that interface, if anything happens as a result that causes loss of property (money, BTW, is considered property for the sake of this definition).
The key idea here is the semantic distinction: the HTTP uniform interface defines that GET is safe
Request methods are considered "safe" if their defined semantics are essentially read-only; i.e., the client does not request, and does not expect, any state change on the origin server as a result of applying a safe method to a target resource. Likewise, reasonable use of a safe method is not expected to cause any harm, loss of property, or unusual burden on the origin server.
The server can handle the request any way that it likes (including, for example, logging all of those requests).作者: VoiceOfUnreason 发布者: 2017 年 12 月 28 日