Call with fetch()
Send parameterized SQL from any runtime with standards-compatible HTTP support.
Open-Source TypeScript Infrastructure
A self-hosted bridge for serverless, edge, workflow, and sandboxed runtimes that can call fetch() but cannot open a PostgreSQL connection.
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
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.
fetch()Send parameterized SQL from any runtime with standards-compatible HTTP support.
The gateway verifies scoped keys, applies limits, and safely reuses warm PostgreSQL sessions.
Dedicated login roles make PostgreSQL the final authorization boundary for every query.
Execution Modes
Interactive reads and short writes with a direct JSON response.
POST /query
Durable execution records in PostgreSQL for work that outlives the request.
type: "async"
Send up to 100 statements with idempotency keys and commit as one transaction.
POST /transaction/execute
Add, inspect, and remove statements before making the final commit decision.
POST /transaction
Defense in Depth
API keys define the requested scope. Dedicated PostgreSQL roles enforce it again at the database boundary.
Quick Start
Configure your database URL in .env and optionally Redis in gateway.yaml. Initial startup prints an auto-generated administrator password.
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
Connect Cursor, Claude, or any MCP-compatible client directly to the live documentation server over Streamable HTTP.
Browse documentation{
"mcpServers": {
"http-postgres-docs": {
"url": "https://http-postgres.harshcodez.com/mcp"
}
}
}