Quickstart
5-Minute Quickstart
This guide starts a local HTTP PostgreSQL Gateway, configures a disposable PostgreSQL database with restricted privileges, creates a least-privilege API key, and runs an authenticated SQL query over HTTP.
The gateway process needs network access to PostgreSQL. Your serverless or edge application does not — it communicates with the gateway over standard HTTPS.
1. Prerequisites
Before starting, ensure your system meets the minimum requirements:
- Node.js:
22.13+on the 22.x line, or23.4+, with built-innode:sqliteenabled. - npm: Version 10 or later.
- PostgreSQL: Version 14 or higher with administrator access.
- Redis: Optional for local development; required for shared rate limiting across multi-process clusters.
Verify your Node.js and SQLite runtime:
node --version
node -e "import('node:sqlite').then(() => console.log('✓ node:sqlite available'))"2. Install & Configure
Clone the repository and install dependencies:
git clone https://github.com/http-postgres/http-postgres.git
cd http-postgres
npm ci
cp .env.example .envConfigure your PostgreSQL administrator connection in .env:
DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/postgres
REDIS_URL=redis://127.0.0.1:6379Local Development Without Redis
If you do not have Redis running locally, disable it in gateway.yaml:
redis:
enabled: falseWhen Redis is disabled, rate limits operate in-memory local to the process.
3. Prepare a Disposable Database
Run the following SQL script as a PostgreSQL superuser. Use a development database where revoking public privileges is safe:
-- Create an isolated demo database
CREATE DATABASE gateway_demo;
-- Revoke default PUBLIC connection rights
REVOKE CONNECT ON DATABASE postgres, template1, gateway_demo FROM PUBLIC;
GRANT CONNECT ON DATABASE gateway_demo TO postgres;
\connect gateway_demo
-- Revoke default schema creation rights
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
-- Create a sample table
CREATE TABLE public.messages (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
message text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now()
);
-- Insert sample records
INSERT INTO public.messages (message) VALUES
('Hello from HTTP PostgreSQL Gateway'),
('Serverless connection pooling works!');PUBLIC has default access in PostgreSQL, revoking public access is necessary. The gateway rejects creating narrow scopes if broader inherited grants make them unsafe.4. Start the Gateway
Start the development server with live reload:
npm run devDuring the very first startup, the gateway generates and prints a secure administrator password:
==================================================================
GENERATED GATEWAY ADMIN PASSWORD:
a7e8f9b2c3d4e5f60123456789abcdef...
==================================================================In another terminal, test the unauthenticated public liveness route:
curl --fail-with-body http://localhost:8080/healthExpected response:
{"status":"ok"}5. Create a Scoped API Key
Generate an API key with read-only (r) access to the public.messages table. Replace <admin-password> with the password saved from Step 4:
curl --fail-with-body http://localhost:8080/admin/keys \
-H 'x-admin: <admin-password>' \
-H 'content-type: application/json' \
-d '{
"database": ["gateway_demo"],
"tables": ["public.messages"],
"scope-table": ["r"]
}'Response:
{
"success": true,
"data": {
"id": "key_01jh9x8q...",
"apiKey": "pg_gw_live_9a8b7c6d5e...",
"environment": "LIVE",
"databases": ["gateway_demo"],
"createdAt": "2026-11-23T06:00:00.000Z"
}
}data.apiKey immediately. Subsequent key list queries return metadata only, never the original secret key.6. Run Your First HTTP Query
Execute a parameterized SQL query using the scoped API key:
curl --fail-with-body http://localhost:8080/query \
-H 'x-api-key: <api-key>' \
-H 'x-database: gateway_demo' \
-H 'content-type: application/json' \
-d '{
"query": "SELECT id, message, created_at FROM public.messages WHERE id = $1",
"parameters": [1]
}'Response:
{
"success": true,
"data": {
"database": "gateway_demo",
"command": "SELECT",
"rowCount": 1,
"rows": [
{
"id": 1,
"message": "Hello from HTTP PostgreSQL Gateway",
"created_at": "2026-11-23T06:00:00.000Z"
}
],
"fields": [
{"name": "id", "dataTypeID": 20},
{"name": "message", "dataTypeID": 25},
{"name": "created_at", "dataTypeID": 1184}
],
"durationMs": 3.42
}
}Notice that parameters are passed safely as an array, eliminating SQL injection risks and keeping untrusted values out of analytics logs.
7. Inspect Operational Health
Run a deep health inspection of all gateway subsystems:
curl --fail-with-body http://localhost:8080/admin/health \
-H 'x-admin: <admin-password>'This returns metrics for PostgreSQL connectivity, pool utilization, unverified connection age, and storage subsystems.
Startup Troubleshooting
| Symptom | Cause | Resolution |
|---|---|---|
node:sqlite requirement error | Node.js is outdated or built without SQLite | Upgrade to Node.js 22.13+ or 23.4+ |
Failed to connect to PostgreSQL | Incorrect credentials or database offline | Check DATABASE_URL in .env and verify PostgreSQL service status |
Redis connection error | Redis is unreachable | Start Redis or set redis.enabled: false in gateway.yaml |
Missing environment variable | Variable not defined in .env | Add the variable or specify a fallback ${VAR:-fallback} in gateway.yaml |
UNSAFE_DATABASE_SCOPE (409) | PostgreSQL PUBLIC grants are too broad | Revoke CONNECT and CREATE privileges from PUBLIC on the target database |
What's Next?
- Integrate with your frontend or serverless framework in Serverless Integration.
- Learn how CRUD Scopes protect your data.
- Explore Atomic Transactions with idempotency keys.
