如何创建幂等端点

How to create idempotent endpoint

我知道 PUT 是幂等的,但我如何以编程方式确保它?我必须满足什么条件才能创建完全幂等的端点?

From a RESTful service standpoint, for an operation (or service call) to be idempotent, clients can make that same call repeatedly while producing the same result. In other words, making multiple identical requests has the same effect as making a single request. Note that while idempotent operations produce the same result on the server (no side effects), the response itself may not be the same (e.g. a resource's state may change between requests).

A PUT 应该使用请求正文中收到的新值更新资源。因此,无论是只发送一次还是几次,服务器上的结果都不应该改变(不像 POST,例如,更多的请求将导致冲突错误或创建多个资源) .