Skip to content

gitstq/api-bridge

Repository files navigation

🚀 API-Bridge

Zero-config API gateway - Turn any local service into REST API instantly

简体中文 | 繁體中文 | 日本語

Python 3.8+ MIT License FastAPI


🎉 Project Introduction

API-Bridge is a lightweight, high-performance API gateway that allows you to instantly expose any local service as a REST API with zero configuration. Whether you're developing microservices, integrating legacy systems, or building API proxies, API-Bridge provides a simple yet powerful solution.

💡 Why API-Bridge?

  • 🚀 Zero Configuration: Start proxying services with a single command
  • ⚡ High Performance: Built on FastAPI and Uvicorn for maximum throughput
  • 🔐 Security First: Built-in API key management and JWT authentication
  • 📊 Observability: Prometheus metrics and real-time monitoring
  • 🔄 Smart Caching: Automatic response caching with TTL support
  • ⚖️ Load Balancing: Weighted round-robin backend selection

🌟 Inspiration

API-Bridge was inspired by the growing need for simple, lightweight API gateways in microservice architectures. While existing solutions like Kong and Nginx are powerful, they often require complex configuration. API-Bridge fills the gap by providing essential gateway features with minimal setup.


✨ Core Features

🚀 Zero-Config Proxy

  • Start proxying any service with one command
  • Automatic route discovery and configuration
  • Support for HTTP/HTTPS backends

🔐 Built-in Authentication

  • API Key Management: Create, revoke, and manage API keys dynamically
  • JWT Support: Token-based authentication with configurable expiration
  • Flexible Authorization: Role-based access control

📊 Real-time Monitoring

  • Prometheus Metrics: Export metrics for monitoring stacks
  • Request Statistics: Track latency, throughput, and error rates
  • Health Checks: Automatic backend health monitoring

🔄 Smart Caching

  • Response Caching: Cache GET responses with configurable TTL
  • Cache Invalidation: Programmatic cache management
  • Cache Hit Metrics: Monitor cache effectiveness

⚖️ Load Balancing

  • Weighted Round-Robin: Distribute traffic across backends
  • Health-Aware Routing: Skip unhealthy backends automatically
  • Dynamic Backend Management: Add/remove backends at runtime

🛠️ Developer Experience

  • Rich CLI: Beautiful command-line interface with progress indicators
  • Hot Reload: Auto-restart during development
  • Comprehensive Logging: Structured JSON logging

🚀 Quick Start

📋 Requirements

  • Python 3.8 or higher
  • pip or pipenv

📦 Installation

# Install from PyPI
pip install api-bridge

# Or install from source
git clone https://github.com/gitstq/api-bridge.git
cd api-bridge
pip install -e ".[dev]"

🏃 Quick Start Commands

# Start the gateway with default settings
api-bridge start

# Proxy a specific service
api-bridge proxy https://api.example.com --path /api

# Start with custom port
api-bridge start --port 3000 --reload

# Generate configuration file
api-bridge config --output .env

🌐 Access Points

Once running, the following endpoints are available:

Endpoint Description
http://localhost:8080 Main proxy endpoint
http://localhost:8080/health Health check
http://localhost:8080/stats Gateway statistics
http://localhost:8080/metrics Prometheus metrics

📖 Detailed Usage Guide

🔧 Configuration

API-Bridge can be configured via environment variables or a .env file:

# Server settings
API_BRIDGE_HOST=0.0.0.0
API_BRIDGE_PORT=8080

# Security
API_BRIDGE_API_KEYS=your-key-1,your-key-2
API_BRIDGE_JWT_SECRET=your-secret

# Features
API_BRIDGE_CACHE_ENABLED=true
API_BRIDGE_CACHE_TTL=300
API_BRIDGE_RATE_LIMIT_ENABLED=true

🛣️ Route Management

# Add a route via API
curl -X POST http://localhost:8080/routes \
  -H "Content-Type: application/json" \
  -d '{
    "path": "/my-service",
    "backends": [
      {
        "name": "backend-1",
        "url": "http://localhost:3001",
        "weight": 2
      },
      {
        "name": "backend-2",
        "url": "http://localhost:3002",
        "weight": 1
      }
    ]
  }'

# List all routes
curl http://localhost:8080/routes

# Delete a route
curl -X DELETE http://localhost:8080/routes/my-service

🔑 API Key Management

# Create an API key
curl -X POST http://localhost:8080/keys \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-app",
    "permissions": ["read", "write"],
    "expires_in_days": 30
  }'

# List API keys
curl http://localhost:8080/keys

# Revoke an API key
curl -X DELETE http://localhost:8080/keys/{key_id}

🧪 Example: Proxying HTTPBin

# Start API-Bridge
api-bridge start

# In another terminal, test the proxy
curl http://localhost:8080/httpbin/get
curl -X POST http://localhost:8080/httpbin/post \
  -H "Content-Type: application/json" \
  -d '{"test": "data"}'

💡 Design Philosophy

🎯 Simplicity First

API-Bridge prioritizes ease of use. Complex configuration is optional - the gateway works out of the box with sensible defaults.

Performance Matters

Built on FastAPI and Uvicorn, API-Bridge handles thousands of concurrent connections with minimal overhead.

🔒 Security by Default

Authentication and rate limiting are enabled by default. Production deployments are secure from day one.

📈 Observable

Every request is tracked. Prometheus metrics provide insights into traffic patterns and performance.


🗺️ Roadmap

✅ Completed (v1.0.0)

  • Core proxy functionality
  • API key management
  • Response caching
  • Prometheus metrics
  • CLI interface
  • Load balancing

🚧 In Progress

  • WebSocket proxy support
  • GraphQL gateway features
  • Plugin system

📋 Planned

  • Kubernetes operator
  • Web-based dashboard
  • gRPC proxy support
  • Service mesh integration

📦 Deployment Guide

🐳 Docker

FROM python:3.11-slim

WORKDIR /app
COPY . .
RUN pip install -e "."

EXPOSE 8080

CMD ["api-bridge", "start", "--host", "0.0.0.0"]

☸️ Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-bridge
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api-bridge
  template:
    metadata:
      labels:
        app: api-bridge
    spec:
      containers:
      - name: api-bridge
        image: api-bridge:latest
        ports:
        - containerPort: 8080
        env:
        - name: API_BRIDGE_PORT
          value: "8080"

🏠 Systemd Service

[Unit]
Description=API-Bridge Gateway
After=network.target

[Service]
Type=simple
User=api-bridge
WorkingDirectory=/opt/api-bridge
ExecStart=/usr/local/bin/api-bridge start
Restart=always

[Install]
WantedBy=multi-user.target

🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

🏗️ Development Setup

# Clone repository
git clone https://github.com/gitstq/api-bridge.git
cd api-bridge

# Create virtual environment
python -m venv venv
source venv/bin/activate

# Install dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
black api_bridge tests
isort api_bridge tests

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🙏 Acknowledgments

  • FastAPI - The amazing web framework
  • Uvicorn - Lightning-fast ASGI server
  • Typer - CLI framework
  • Rich - Beautiful terminal output

Made with ❤️ by gitstq

About

🚀 Zero-config API gateway - Turn any local service into REST API instantly

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages