且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

REST 请求的 GET 或 PUT

更新时间:2022-03-10 05:03:06

理论上 GET 应该只是 GET,而不是改变你的系统状态.请参阅幂等性.

Theoretically GET should just GET, and not change the state of your system. See idempotency.

来自***的段落:

某些方法(例如 HEAD、GET、OPTIONS 和 TRACE)被定义为安全的,这意味着它们仅用于信息检索,不应更改服务器的状态.

Some methods (for example, HEAD, GET, OPTIONS and TRACE) are defined as safe, which means they are intended only for information retrieval and should not change the state of the server.

但是,在您的场景中,初始 GET 正在设置一个纯粹用于缓存的资源.后续调用不会改变系统的状态,因此我建议在这种情况下使用 GET.

However, in your scenario an initial GET is setting up a resource purely for caching. Subsequent calls won't change the state of the system, so I'd suggest that GET is fine in this scenario.