第 7 章

HTTP

构建请求,配置超时与重试,并处理响应。

请求管道

example.hhy
http.get("https://example.com/users")
    |> timeout(5s)
    |> retry({ count: 3, backoff: 200ms })
    |> send
    |> response_body
    |> parse_json
    |> print

http.get/post/put/delete 创建不可变 RequestPlan;timeout 与 retry 修改计划;send 才执行网络副作用。response_body 会验证状态码并返回文本。

V1.0 边界

  • 支持 query、header、body、proxy 与 redirect 选项
  • 支持文本和二进制响应
  • 响应体默认上限 16 MiB
  • dry-run 只输出脱敏计划,不发送请求