go-httpbin(1)

著名的 httpbin.org HTTP 请求与响应测试服务的 Golang 版本。

API端点

说明

测试HTTP库有时会变得困难。RequestBin 对于测试POST请求来说很棒,但不能让你控制响应。这个服务的存在就是为了覆盖各种HTTP场景。正在考虑其他端点。

所有端点响应都是JSON编码的。

🆕 新功能

自定义状态码的/anything端点

现在支持通过 /anything/status/{code} 端点返回自定义状态码,同时保持/anything的所有功能。

反向代理功能

通过设置 REPORT_BE 环境变量启用 /internal_report_viewer/ 端点的反向代理功能:

export REPORT_BE=backend.example.com:8080
# 然后访问 /internal_report_viewer/any/path 将被代理到 backend.example.com:8080/any/path

使用示例

$ curl https://httpbingo.org/ip

{"origin":"73.238.9.52, 77.83.142.42"}

$ curl https://httpbingo.org/user-agent

{"user-agent":"curl/7.64.1"}

$ curl https://httpbingo.org/get?foo=bar

{
  "args": {
    "foo": [
      "bar"
    ]
  },
  "headers": {
    "Accept": [
      "*/*"
    ],
    "Host": [
      "httpbingo.org"
    ],
    "User-Agent": [
      "curl/7.64.1"
    ]
  },
  "origin": "73.238.9.52, 77.83.142.42",
  "url": "https://httpbingo.org/get?foo=bar"
}

🆕 $ curl https://httpbingo.org/anything/status/404

HTTP/1.1 404 Not Found
{
  "args": {},
  "data": "",
  "files": {},
  "form": {},
  "headers": {
    "Accept": [
      "*/*"
    ],
    "Host": [
      "httpbingo.org"
    ],
    "User-Agent": [
      "curl/7.64.1"
    ]
  },
  "method": "GET",
  "origin": "73.238.9.52",
  "url": "https://httpbingo.org/anything/status/404"
}

$ curl -I https://httpbingo.org/status/418

HTTP/1.1 418 I'm a teapot
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
X-More-Info: http://tools.ietf.org/html/rfc2324
Date: Tue, 13 Jul 2021 13:12:37 GMT
Content-Length: 0

作者

Will McCutchen 移植到Go。

基于 原版 Kenneth Reitz 项目。

另请参阅

httpbin.org — 原版 httpbin