HTTP Request and Response Service

0.10.2 · active · verified Wed Apr 15

httpbin is an open-source HTTP request and response service, implemented in Python using Flask. It provides various endpoints that echo back client requests, return specific status codes, headers, or dynamic data, making it invaluable for testing HTTP clients, debugging webhooks, and understanding HTTP protocol concepts. The current version, 0.10.2, is actively maintained by the Python Software Foundation (PSF) and has seen several recent releases, including a major fork from its original maintainer due to inactivity.

Warnings

Install

Imports

Quickstart

To use httpbin, you typically run it as a WSGI application. The most common way is with a WSGI server like Gunicorn, which serves the `httpbin:app` object. For development or quick testing, you can also run it directly as a module. The provided code includes instructions for both running the service and a Python example (using the 'requests' library) demonstrating how to interact with an httpbin instance, typically the public httpbin.org service.

import os

# To run httpbin as a standalone WSGI application using Gunicorn:
# 1. Ensure you have httpbin installed with the 'mainapp' extra:
#    pip install 'httpbin[mainapp]' gunicorn
# 2. Run the following command in your terminal:
#    gunicorn httpbin:app

# Alternatively, for a simple direct run (for development/testing):
# 1. Ensure httpbin is installed:
#    pip install httpbin
# 2. Run the following command in your terminal:
#    python -m httpbin.core

# Example of interacting with a running httpbin instance (using requests library):
# (This code is for demonstration, it interacts with httpbin.org, not your local instance)
import requests

base_url = "https://httpbin.org"

# Make a GET request and inspect the response
response_get = requests.get(f"{base_url}/get?key=value")
print(f"GET Status: {response_get.status_code}")
print(f"GET JSON: {response_get.json()['args']}")

# Make a POST request with JSON data
post_data = {"name": "test", "id": 123}
response_post = requests.post(f"{base_url}/post", json=post_data)
print(f"POST Status: {response_post.status_code}")
print(f"POST JSON: {response_post.json()['json']}")

view raw JSON →