跳到主要内容

4.11. 发出多个 Request

4.11. 发出多个 Request (Making Multiple Requests)

client 经常需要发出多个 HTTP request 才能完成一项任务. 规定此类 behavior 时, application 需要考虑:

  • Request ordering: 如果 request 需要按特定顺序发出, 应清楚规定.

  • Error handling: 如果序列中的某个 request 失败, 应发生什么?

  • Atomicity: 如果一系列 request 应作为 atomic unit 处理, 如何确保这一点?

  • Performance: 发出许多 sequential request 可能很慢. application 应考虑如何最小化 round trip.

application SHOULD:

  • 尽可能允许并行发出 request, 而不是要求严格排序.

  • 清楚规定 request 之间的任何 dependency.

  • 在适当时考虑使用 batch 或 compound operation, 以减少所需 request 数量.

  • 意识到 HTTP/2 [HTTP/2] 和 HTTP/3 [HTTP/3] 允许多个 request 在单个 connection 上同时 in flight, 这可以显著提升需要发出多个 request 的 application 的性能.

application SHOULD NOT 假定多个 request 会由同一 server instance 处理或按特定顺序处理, 除非 application 通过使用 state 或其他 mechanism 显式协调这一点.