Open-Source TypeScript Infrastructure

PostgreSQL,
available over HTTP.

A self-hosted bridge for serverless, edge, workflow, and sandboxed runtimes that can call fetch() but cannot open a PostgreSQL connection.

edge-function.ts
const response = await fetch(`${PG_GATEWAY_URL}/query`, {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "x-api-key": PG_API_KEY,
    "x-database": "app"
  },
  body: JSON.stringify({
    query: "SELECT * FROM messages WHERE id = $1",
    parameters: [42]
  })
});

Architecture

Keep the database driver where it belongs.

Short-lived runtimes are built for HTTP, not long-lived database sockets. Run the gateway beside PostgreSQL and give remote functions a clean JSON API.

Call with fetch()

Send parameterized SQL from any runtime with standards-compatible HTTP support.

Authenticate and pool

The gateway verifies scoped keys, applies limits, and safely reuses warm PostgreSQL sessions.

Let PostgreSQL decide

Dedicated login roles make PostgreSQL the final authorization boundary for every query.

Execution Modes

One gateway. Four ways to run.

API reference
Immediate

Query and respond

Interactive reads and short writes with a direct JSON response.

POST /query
Asynchronous

Submit and poll

Durable execution records in PostgreSQL for work that outlives the request.

type: "async"
Atomic Batch

Commit together

Send up to 100 statements with idempotency keys and commit as one transaction.

POST /transaction/execute
Queued

Build incrementally

Add, inspect, and remove statements before making the final commit decision.

POST /transaction

Defense in Depth

Access is scoped twice.

API keys define the requested scope. Dedicated PostgreSQL roles enforce it again at the database boundary.

  • Revocable keys restricted by database, table, and CRUD operation
  • Dedicated PostgreSQL roles created for scoped access
  • Adaptive pool growth, query timeouts, bounded results, and rate limits
  • Versioned SQLite metadata with WAL concurrency and query analytics

Quick Start

From clone to ready.

Configure your database URL in .env and optionally Redis in gateway.yaml. Initial startup prints an auto-generated administrator password.

Full setup guide
Terminal
git clone https://github.com/http-postgres/http-postgres
cd http-postgres
npm ci
cp .env.example .env
npm run dev
curl http://localhost:8080/health/ready

Model Context Protocol

Documentation built for AI tools.

Connect Cursor, Claude, or any MCP-compatible client directly to the live documentation server over Streamable HTTP.

list-pages get-page Streamable HTTP
Browse documentation
mcp.json
{
  "mcpServers": {
    "http-postgres-docs": {
      "url": "https://http-postgres.harshcodez.com/mcp"
    }
  }
}

Bring PostgreSQL to the runtimes that cannot reach it.