Skip to content

MichelFortes/httpbin

Repository files navigation

What is it?

HTTPBin is a server that helps you debug HTTP requests.

Environment variables

This application expects to receive the following environment variables:

  • HTTPBIN_SERVICE_ID (default: "")
  • HTTPBIN_SERVICE_PORT (default: "8888")

Features

You can determine the server's behavior for a specific request-response cycle by sending predefined configuration headers, as follows:

Set the status code

Header: X-HttpBin-Status

Description: Determine the status code of the response.

Set a response delay

Header: X-HttpBin-Sleep

Description: Determine a response delay in seconds.

Restrict the content-type accepted by the server

Header: X-HttpBin-Content-Type

Description: Requests with payloads must declare their content type as the same as that accepted by the server, otherwise the server will return a 415 (Unsupported Media Type) status code.

Special Features

Proxing request

Use the special path "/proxy" with the query param "to" to set the destination to which the request should be proxied. The response replicates the headers and body the destination server return.

curl -i "http://localhost:8888/proxy?to=https://google.com"

Health Checks

Use the special path "/health" the check service health. It return a simple 200 status code when the service is up and ready.

curl -i "http://localhost:8888/health"

Running

Using go run command

go run cmd/httpbin/main.go

Using docker compose

docker compose -f deployments/docker-compose.yml up --build

Output Example

A JSON containing information about the request and the Container where the application is running.

curl -i "localhost:8888/some-path?products=notebook&products=tablet&customer=john"
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Tue, 09 Jan 2024 13:41:57 GMT
Content-Length: 267
{
  "serviceId": "container-01",
  "remoteAddr": "127.0.0.1:57968",
  "method": "GET",
  "path": "/some-path",
  "queryParams": {
    "customer": [
      "john"
    ],
    "products": [
      "notebook",
      "tablet"
    ]
  },
  "headers": {
    "Accept": [
      "*/*"
    ],
    "User-Agent": [
      "curl/7.81.0"
    ]
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published