知识卡片
客户端保存交互状态
跨多个服务的临时应用状态应由发起交互的客户端追踪,因为只有它知道完整调用过程。每次保存请求URL、方法、头、查询与正文,以及响应URL、状态、媒体类型、头及正文,再从历史中提取状态变量。
请求URL与最终响应URL可能因重定向不同,二者都要保留。历史可用栈回看和路径查询;单有日志还不够,须定义业务关注的变量。浏览器可用远程状态服务补足存储,但会引入额外网络延迟与不可用依赖。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 超媒体客户端 · 查看原书依据
The safest place to keep the transient state—the state of the application as defined by runtime requests and responses—is in the client. The client is responsible for selecting which servers are engaged in interactions, and the client is initiating HTTP requests. It is the client, and only the client, that has the most accurate picture of the state of the application.
参考来源
- 位置:《RESTful Web API Patterns and Practices Cookbook》第4章《Hypermedia Clients》(来源项目book-sources:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch04.xhtml,配方4.15)
- 结论依据:原文列出请求和响应历史字段,用栈保存交互,再由路径查询提取状态,并讨论远程存储依赖。
- 原始内容:The safest place to keep the transient state—the state of the application as defined by runtime requests and responses—is in the client. The client is responsible for selecting which servers are engaged in interactions, and the client is initiating HTTP requests. It is the client, and only the client, that has the most accurate picture of the state of the application.