DEV Community

Bridge ACE
Bridge ACE

Posted on

How We Handle 200+ API Endpoints Without a Framework

How We Handle 200+ API Endpoints Without a Framework

Bridge ACE's server handles 200+ explicit URL patterns across GET, POST, PATCH, PUT, and DELETE. No framework. No router library. Pure Python path matching.

Here is how.

The Router Pattern

The HTTP handler is a subclass of http.server.BaseHTTPRequestHandler. Each HTTP method has a handler that matches paths:

def do_GET(self):
    path = self.path.split('?')[0]

    if path == '/status':
        return self._handle_status()
    elif path == '/health':
        return self._handle_health()
    elif path.startswith('/agents/'):
        return self._handle_agent_get(path)
    elif path == '/tasks':
        return self._handle_tasks_list()
    # ... 200+ more patterns
Enter fullscreen mode Exit fullscreen mode

Is this elegant? No. Is it fast, debuggable, and zero-dependency? Yes.

Why Not Use a Router

We considered werkzeug.routing, starlette.routing, or even a simple regex router. The problems:

  1. Dependency: Any router adds a dependency that can break
  2. Magic: URL parameter extraction hides logic
  3. Debugging: When a route fails, you want to see the exact path match, not a framework stack trace
  4. Performance: String comparison is faster than regex for 200 routes

The Handler Module Pattern

To keep server.py manageable, we split route handlers into 37 modules:

from handlers.guardrails_routes import handle_get, handle_post
from handlers.agent_routes import handle_agent_get, handle_agent_post
from handlers.task_routes import handle_task_get, handle_task_post
Enter fullscreen mode Exit fullscreen mode

Each module owns a domain (agents, tasks, guardrails, workflows). The main handler dispatches to the right module based on path prefix.

Authentication

Multi-tier token auth:

# Token from header
token = headers.get('X-Bridge-Token') or headers.get('Authorization', '').replace('Bearer ', '')

# Or injected into HTML responses
html = html.replace('</head>', f'<script>window.__BRIDGE_UI_TOKEN="{token}"</script></head>')
Enter fullscreen mode Exit fullscreen mode

Three permission levels: Public (status, health), Agent (messaging, tasks), Admin (config, restart).

Lock Ordering

With 16 daemon threads and threaded HTTP, lock ordering is critical:

TASK_LOCK → ESCALATION_LOCK → TEAM_CONFIG_LOCK
Enter fullscreen mode Exit fullscreen mode

Never acquire TEAM_CONFIG_LOCK while holding TASK_LOCK. This simple rule prevents all deadlocks.

The Result

A server that:

  • Starts in under 2 seconds
  • Handles concurrent requests from 10+ agents
  • Runs 16 background daemons
  • Has zero framework dependencies
  • Is fully debuggable with print statements

Open Source

All 7,000+ lines are in the repo.

git clone https://github.com/Luanace-lab/bridge-ide.git
Enter fullscreen mode Exit fullscreen mode

GitHub: github.com/Luanace-lab/bridge-ide

Top comments (0)