Convert Figma logo to code with AI

postmanlabs logohttpbin

HTTP Request & Response Service, written in Python + Flask.

12,679
1,801
12,679
187

Top Related Projects

Insomnia Mockbin is the underlying backend for the API mocks capability of Insomnia. It is built and used by Kong, the author of the open-source Kong Gateway.

Get a full fake REST API with zero coding in less than 30 seconds (seriously)

Over the wire test doubles

Quick Overview

httpbin is a simple HTTP request & response service that provides various endpoints for testing and debugging HTTP clients. It allows developers to simulate different HTTP scenarios, test API integrations, and explore various HTTP methods and status codes.

Pros

  • Easy to use and deploy, with a public instance available at httpbin.org
  • Supports a wide range of HTTP methods and status codes
  • Provides endpoints for testing authentication, cookies, and request/response headers
  • Open-source and actively maintained

Cons

  • Limited customization options for advanced use cases
  • May not fully simulate real-world API behavior for complex scenarios
  • Public instance (httpbin.org) may have usage limitations or downtime
  • Some features may require self-hosting for full functionality

Code Examples

  1. Making a GET request:
import requests

response = requests.get('https://httpbin.org/get')
print(response.json())
  1. Sending POST data:
import requests

data = {'key': 'value'}
response = requests.post('https://httpbin.org/post', json=data)
print(response.json())
  1. Testing basic authentication:
import requests

response = requests.get('https://httpbin.org/basic-auth/user/pass', auth=('user', 'pass'))
print(response.status_code)
  1. Simulating a specific status code:
import requests

response = requests.get('https://httpbin.org/status/418')
print(response.status_code)

Getting Started

To use httpbin in your project, you can simply make HTTP requests to the public instance at httpbin.org. For example:

import requests

# Make a GET request
response = requests.get('https://httpbin.org/get')
print(response.json())

# Send POST data
data = {'key': 'value'}
response = requests.post('https://httpbin.org/post', json=data)
print(response.json())

# Test different status codes
response = requests.get('https://httpbin.org/status/404')
print(response.status_code)

For more advanced usage or to run your own instance, you can clone the repository and follow the installation instructions in the project's README.

Competitor Comparisons

Insomnia Mockbin is the underlying backend for the API mocks capability of Insomnia. It is built and used by Kong, the author of the open-source Kong Gateway.

Pros of insomnia-mockbin

  • More extensive API mocking capabilities, including custom responses and dynamic data
  • Better integration with Insomnia, a popular API development tool
  • Supports WebSocket connections for real-time API testing

Cons of insomnia-mockbin

  • Less widely adopted compared to httpbin
  • May have a steeper learning curve for users unfamiliar with Insomnia
  • Fewer built-in endpoints for common HTTP testing scenarios

Code Comparison

httpbin:

@app.route('/ip')
def get_ip():
    return jsonify(origin=request.remote_addr)

insomnia-mockbin:

app.get('/ip', (req, res) => {
  res.json({ ip: req.ip });
});

Both repositories provide similar functionality for basic IP address retrieval, but insomnia-mockbin offers more flexibility in customizing responses and handling various HTTP methods.

httpbin is written in Python and uses Flask, while insomnia-mockbin is built with Node.js and Express. This difference in technology stack may influence developers' choice based on their preferred programming language and ecosystem.

Overall, httpbin is simpler and more straightforward for basic HTTP testing, while insomnia-mockbin offers more advanced features and better integration with the Insomnia API development environment.

Get a full fake REST API with zero coding in less than 30 seconds (seriously)

Pros of json-server

  • Provides a full fake REST API with zero coding
  • Supports custom routes and middlewares
  • Allows for easy data persistence and database-like operations

Cons of json-server

  • Limited to JSON data and REST APIs only
  • Lacks advanced features like authentication simulation or request inspection
  • May not accurately represent real-world API behavior in all scenarios

Code Comparison

httpbin:

@app.route('/get', methods=('GET',))
def view_get():
    """The request's query parameters."""
    return jsonify(get_dict(
        'url', 'args', 'headers', 'origin', 'json'))

json-server:

const jsonServer = require('json-server')
const server = jsonServer.create()
const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()

server.use(middlewares)
server.use(router)
server.listen(3000, () => {
  console.log('JSON Server is running')
})

Key Differences

  • httpbin is more focused on testing various HTTP scenarios and request/response inspection
  • json-server is designed for quickly mocking a full REST API based on a JSON file
  • httpbin offers a wider range of endpoints for different HTTP methods and behaviors
  • json-server provides more database-like features such as filtering, pagination, and relationships

Both tools are valuable for API testing and development, but they serve slightly different purposes and use cases.

Over the wire test doubles

Pros of Mountebank

  • More comprehensive mocking capabilities, including TCP and HTTPS protocols
  • Supports stateful behavior and complex response scenarios
  • Provides a CLI and API for easier integration into development workflows

Cons of Mountebank

  • Steeper learning curve due to more advanced features
  • Requires more setup and configuration compared to Httpbin's simplicity
  • Less suitable for quick, ad-hoc HTTP testing

Code Comparison

Httpbin (Python):

@app.route('/get', methods=['GET'])
def get_request():
    return jsonify(
        url=request.url,
        args=request.args,
        headers=dict(request.headers),
        origin=request.remote_addr,
    )

Mountebank (JavaScript):

function setupImposter() {
  return {
    port: 4545,
    protocol: 'http',
    stubs: [{
      predicates: [{ equals: { method: 'GET', path: '/get' } }],
      responses: [{
        is: {
          statusCode: 200,
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({
            url: 'http://localhost:4545/get',
            args: {},
            headers: { /* ... */ },
            origin: '127.0.0.1'
          })
        }
      }]
    }]
  };
}

Both repositories serve as HTTP request & response testing tools, but Mountebank offers more advanced mocking capabilities at the cost of increased complexity. Httpbin is simpler and more straightforward for basic HTTP testing, while Mountebank provides a more powerful solution for complex scenarios and multiple protocols.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

httpbin(1): HTTP Request & Response Service

A Kenneth Reitz Project.

ice cream

Run locally:

docker pull kennethreitz/httpbin
docker run -p 80:80 kennethreitz/httpbin

See http://httpbin.org for more information.

Officially Deployed at:

SEE ALSO

Build Status

Build Status