View Categories

How to Expose a PostgreSQL Database as a Secure REST API

11 min read

PostgreSQL logo POSTGRESQL REST API

Turn a PostgreSQL query into a secure REST API — no PostgREST, no server to host.

Save a SQL query against your Postgres database, mint a per-recipient API key, and hand a partner a live JSON endpoint. No open 5432 port, no shared credentials, no Express service to build and patch — just a governed, read-only Postgres REST API in minutes.

No inbound ports Per-recipient keys Read-only enforced Nothing to deploy

Query Streams is a secure, real-time database integration platform that turns any saved PostgreSQL query into a partner-ready REST API endpoint — with per-recipient keys, read-only enforcement, and a full audit trail. You get a live Postgres REST API without opening a database port, sharing credentials, or hosting a gateway. Learn more at QueryStreams.com and sign up for free to publish your first PostgreSQL endpoint in minutes.

Why expose a PostgreSQL database as a REST API?

Sooner or later, someone outside your team needs data that lives in PostgreSQL — a client wants their numbers in a dashboard, a vendor wants a live feed instead of a nightly CSV, a partner’s app needs to read a slice of your tables. The usual answers all leak something you would rather keep: you email exports that are stale the moment they land, you hand out a read-only psql login that outlives the engagement, or you stand up a small service and inherit its auth, TLS, and patching forever. A PostgreSQL REST API is the clean version of this — the partner gets a URL and a token, not your database. The hard part has always been building and operating that API safely. Query Streams makes it a saved query plus a key.

No open Postgres port

You never expose 5432 to the internet or poke a hole in your firewall. The Network Agent dials out; inbound calls ride back down that one outbound connection.

Per-recipient API keys

Every recipient gets their own qsapi_* key. Revoke one without touching the others, and without rotating your PostgreSQL password.

Read-only by design

A read-only validator rejects any non-SELECT statement before it reaches Postgres. There is no accidental UPDATE or DROP path through the API.

Your SQL stays private

The recipient sees the endpoint URL, the JSON response, and any filters you exposed — never your SQL, schema, hostname, or connection string.

Nothing to host or patch

No PostgREST container, no Express app, no reverse proxy. The endpoint runs as a managed feature, so there is no deploy pipeline or TLS rotation to own.

Permanent, expiring, or self-destructing

Make an endpoint permanent, set it to expire on a date, or give it a fixed call budget that self-destructs after a set number of requests.

The usual ways to put a REST API on Postgres — and why they hurt

There are well-known tools for this, and they are good at what they do. The catch is that every one of them leaves you owning infrastructure, a network exposure, or both. Here is how the common approaches compare to a Query Streams shared endpoint when the goal is simply “let a specific partner read a specific result set.”

Concern PostgREST / Hasura (self-hosted) DIY Express / FastAPI Query Streams
Database reachable from the API Must reach Postgres (often a new network path / public port) Must reach Postgres Outbound-only Agent — no inbound port
What the recipient holds A URL into your schema A URL into your service A single-purpose key for one query
Schema exposure Whole schema exposed by default Whatever you hand-code One saved query, nothing else
Per-recipient keys + revoke Build it yourself Build it yourself Built in
Audit log of every call Add it yourself Add it yourself Built in
You operate / patch / rotate TLS Yes, forever Yes, forever Managed for you
Time to first endpoint Hours to days Days Minutes

Looking for a PostgREST alternative for partner sharing?

PostgREST is excellent when you want a full, self-hosted REST surface over your own schema. If instead you want to hand a named partner one governed, read-only result set — with its own key, an audit trail, and no server to run — that is exactly the gap Query Streams fills. The two can coexist: PostgREST for your internal app, Query Streams for outbound sharing.

How Query Streams turns a Postgres query into a REST API

Once the Network Agent is installed and your PostgreSQL connector is configured, promoting a saved query to a shared REST endpoint takes about three steps. If you already use Query Streams for Excel, Google Sheets, or the MCP Server, your Agent and connector are already in place — you start at step two.

1

Connect PostgreSQL through the Agent

Install the Network Agent next to your database and add a PostgreSQL connector with a standard read-only role. The Agent makes an outbound TLS connection to Query Streams — your database is never exposed to the internet.

2

Save a SQL query

Write the SELECT in the Query Builder against your Postgres connection — JOINs, CTEs, window functions, and parameters all welcome. Name it and save. Anything you can SELECT can become an endpoint.

3

Promote it and share a key

Open the Install tab, choose the endpoint type (permanent, expiring, or call-budget) and output format, then invite a recipient by email. They get a magic-link claim and their own qsapi_* key.

One saved query, many surfaces

The same saved PostgreSQL query can drive an Excel refresh, a Google Sheets sidebar, a Claude or Cursor conversation through the PostgreSQL MCP Server, and a partner-facing REST endpoint at the same time. You build the query once; Query Streams handles the surfaces.

No open Postgres port, no shared credentials

The security model is the reason teams reach for this instead of a public database port. Your PostgreSQL password lives only inside the Agent’s encrypted credential store on your network; it is never transmitted to our cloud and never visible to a recipient. On top of that, every endpoint gives you per-recipient controls you can tighten before you share.

Outbound-only Agent

The Agent connects out to agent.querystreams.com on port 443. Your firewall sees normal outgoing HTTPS — no inbound ports, no VPN, no tunnel.

Read-only enforcement

A validator runs in the Agent, on your network, before any statement reaches Postgres. Non-SELECT statements are rejected with READONLY_VIOLATION.

IP + CORS allowlists

Pin a recipient’s key to specific IPs or CIDR ranges, and restrict which browser origins may call each endpoint. Off-list calls are refused before any SQL runs.

Rate limits + byte quotas

Two-tier rate limits (per key and per endpoint) plus an optional monthly byte cap keep a noisy or runaway recipient inside a safe blast radius.

Call your PostgreSQL REST API

Recipients call the endpoint like any other REST API: a bearer token and a URL. Any saved-query parameter you exposed can be set per call — on the querystring for GET or in a JSON body for POST. The Agent binds those values as proper prepared-statement parameters, never string concatenation, so a recipient cannot break out of a filter to inject SQL.

GET with a filter parameter
# Recipient call against your Postgres-backed endpoint curl -H “Authorization: Bearer qsapi_K7…ZmQ” \ “https://api.querystreams.com/v1/endpoints/orders-by-region?region=EMEA&since=2026-01-01”

Pick the output format per call with the Accept header (or a ?format= query parameter): JSON for a single array, CSV for spreadsheets and pandas, or, on a streaming endpoint, NDJSON (one JSON row per line) for parse-as-you-go pipelines. For bandwidth-sensitive consumers, opt into LZ4 payload compression with Accept-Encoding: lz4; uncompressed responses also get standard gzip on the wire automatically. For the full breakdown of static vs streaming modes, the four wire combinations, and OpenAPI 3.1 generation, see the Instant REST API for SQL databases guide.

How usage is billed

The API Platform is included in every plan and draws from the same monthly byte allowance as Excel, Google Sheets, and the MCP Server — LZ4 calls bill on compressed bytes, otherwise on uncompressed. how the shared byte allowance is metered →

Plug it into Power BI, Tableau, and anything that reads JSON

Because every endpoint returns standard JSON — with CSV and streaming NDJSON on tap — any tool that can read a REST feed consumes your PostgreSQL data directly, with nothing to install on their side. Power Query is the easiest bridge into the Microsoft BI stack: in Power BI choose Get Data → From Web, paste the endpoint URL, add your Authorization header, and Power Query parses the JSON into a refreshable table that feeds your data model. (For live data inside a spreadsheet, the native Query Streams Excel add-on is the simpler path — Power Query is there when you want the data in the Power BI model itself.)

Microsoft Power Query logo Power Query Get Data → From Web, paste the URL and bearer token, expand the JSON to a refreshable table
Microsoft Power BI logo Power BI Same Power Query engine — load the endpoint straight into your model and schedule refresh
Tableau logo Tableau Point a Web Data Connector or JSON source at the endpoint for live dashboards
Postman logo Postman Import the OpenAPI 3.1 spec, then send, inspect, and share requests in one click

It also feeds n8n, Qlik, curl, Python (requests or pandas.read_json), Insomnia, Hoppscotch — or any script or workflow that can send an HTTP request and read JSON.

Works with managed Postgres too

It does not matter where your PostgreSQL runs. The Agent connects the same way to an on-premise server or a managed service — Amazon RDS for PostgreSQL and Aurora PostgreSQL, Azure Database for PostgreSQL, Google Cloud SQL for PostgreSQL, Supabase, or Neon. For the lowest latency, deploy the Agent in the same network or region as the database; one Query Streams account can run multiple Agents across regions and clouds, and a single endpoint behaves identically regardless of which Agent serves it.

More than PostgreSQL

The same workflow promotes a saved query from Microsoft SQL Server, MySQL, MariaDB, SQLite, Microsoft Access, Snowflake, Oracle, BigQuery, or DuckDB to a REST endpoint. PostgreSQL is simply one of the most popular starting points. Browse the Connector Setup guides for the current list.

Frequently Asked Questions

Do I need to open a port or expose PostgreSQL to the internet? +
No — the Network Agent dials out over TLS on port 443, so inbound calls ride back down that one outbound connection and your PostgreSQL port (5432 by default) is never exposed. how the outbound-only connection works →
Can the recipient see my SQL or my database credentials? +
Never — the recipient sees only the endpoint URL, the response, and the filters you exposed, while your SQL and PostgreSQL password stay inside the Agent’s encrypted credential store on your network. what stays private behind each key →
How is this different from PostgREST or Hasura? +
PostgREST and Hasura generate a broad API surface over your schema and run as services you host, secure, and keep reachable from Postgres. Query Streams takes the opposite, narrower angle for outbound sharing: you expose one saved query as one endpoint, each recipient gets their own revocable key, every call is audited, and there is nothing for you to deploy or patch. Many teams run both — an internal tool like PostgREST plus Query Streams for sharing data outside the building.
What output formats can the API return? +
JSON (the default), CSV, and — on a streaming endpoint — NDJSON, chosen per call with the Accept header or a ?format= parameter, with optional LZ4 payload compression. the wire formats and compression options →
Can recipients filter the results, or do they get a fixed query? +
You decide. Any parameter you expose in the saved query becomes a filter the recipient can set per call — on the querystring for GET or a JSON body for POST. Parameters you do not expose stay fixed. The Agent binds every value as a prepared-statement parameter, so filters cannot be used to inject SQL.
Can an endpoint expire or self-destruct? +
Yes — an endpoint can be permanent, expire on a date, or carry a fixed call budget, and you can revoke any recipient’s key instantly without touching the others or rotating your database password. endpoint lifetimes and per-recipient key revocation →
Does it work with Amazon RDS, Azure, Cloud SQL, Supabase, or Neon? +
Yes. The Agent connects to any reachable PostgreSQL, whether on-premise or managed — Amazon RDS and Aurora PostgreSQL, Azure Database for PostgreSQL, Google Cloud SQL for PostgreSQL, Supabase, and Neon all work. For best latency, run the Agent in the same region as the database; one account can run multiple Agents across clouds and regions.
Does the recipient need a Query Streams account? +
Sharing by email is recommended — the recipient gets a magic-link claim and an auto-created Free-tier org — or you can issue a service key for unattended machine-to-machine access instead. per-recipient claims versus service keys →

Get Started

Publish your first PostgreSQL REST API for free.

Sign up, install the Network Agent next to your Postgres database, save a SQL query, and email a recipient a magic-link claim. Per-recipient keys, read-only enforcement, and a full audit trail are on from the first call.

Related guides: Instant REST API for SQL databases | Database REST API platform | Connect PostgreSQL to Claude via MCP | Connector Setup guides

Category: API Platform

Tags: postgres-rest-api, postgresql, rest-api, expose-postgres-as-api, postgrest-alternative, share-postgres-data, per-recipient-keys, no-code-api, database-rest-api

Meta Description: Turn a PostgreSQL query into a secure, read-only REST API with per-recipient keys — no open port, no PostgREST, no code.

Updated on June 16, 2026

Powered by BetterDocs