Automatic REST API for PostgreSQL | 6.1x faster than PostgREST
SQL files and PostgreSQL objects become REST endpoints. TypeScript and Dart clients are generated automatically. Tests are SQL files too.
4,500+ req/s on a single host · 2,484 integration tests · 12K LOC SQL in production · MIT licensed
Documentation | Quick Start | Annotations | Configuration | Blog
SQL is declarative — your API should be too. With NpgsqlRest, you write SQL and annotate it with comments to declare what you want from your endpoint: caching, timeouts, retries, authorization, rate limiting, and everything in between. No controllers, no models, no mapping layers. Backend features become simple declarations on your SQL objects, putting PostgreSQL at the dead center of your architecture — the opposite of Clean Architecture, which treats the database as a detail. Here, PostgreSQL is the architecture.
-- sql/process_order.sql
-- HTTP POST
-- @authorize admin
-- @result validate
-- @single
select count(*) as found from orders where id = :order_id;
update orders set status = 'processing' where id = :order_id;
-- @result confirm
select id, status from orders where id = :order_id;That gives you POST /api/process-order:
{"validate": 1, "result2": 1, "confirm": [{"id": 42, "status": "processing"}]}…plus a generated TypeScript client with full type safety. No framework, no ORM, no boilerplate.
- Two endpoint sources — plain
.sqlfiles (drop a file in a folder, get an endpoint) and PostgreSQL functions and procedures, sharing the same 50+ comment annotations:@authorize,@cached,@path,@proxy, and more - Tests are SQL files too —
npgsqlrest --testinvokes the real endpoint pipeline in-process, on the test's own transaction, with endpoint-coverage gating - Watch mode —
--watchrestarts on SQL file, configuration, and even database routine changes; the TypeScript client regenerates every cycle - Typed clients — TypeScript fetch modules with optional TanStack Query (React Query) v5 hooks, and Dart clients for Flutter
- AI-agent ready —
@mcpexposes any endpoint as a Model Context Protocol tool with the same auth and rate limits, plus OpenAI/Anthropic tool schemas and llms.txt - Auth built in — cookie auth, Basic auth, JWT claims, external OAuth, passkeys, role-based
@authorize - Production-grade — response caching, per-endpoint rate limiting, retries, multi-host failover, SSE streaming, file uploads, reverse proxy
- Output formats — JSON, CSV, Excel, HTML table rendering, and OpenAPI 3.0/3.1 spec generation
- AOT-compiled native binaries — zero dependencies, instant startup
| Method | Command |
|---|---|
| NPM | npm install npgsqlrest |
| Bun | bun add --trust npgsqlrest |
| Deno | deno install --allow-scripts=npm:npgsqlrest npm:npgsqlrest |
| Docker | docker pull vbilopav/npgsqlrest:latest |
| Direct Download | Releases |
| .NET Library | dotnet add package NpgsqlRest |
Requires PostgreSQL >= 13. Native executables have zero runtime dependencies. See the Installation Guide.
An official Claude Code skill teaches the agent the exact annotations and configuration options for the current release — install it per project or per user and build endpoints by describing them.
NpgsqlRest is free, MIT-licensed, and built by one person out of passion. If it saves you time, GitHub Sponsors is the primary way to support it — Patreon and Buy Me a Coffee work too. Read more on the support page.
Contributions are welcome — see CONTRIBUTING.md. Small, well-scoped issues are labeled good-first-issue.
Please report vulnerabilities privately via GitHub Private Vulnerability Reporting — see SECURITY.md. Do not open public issues for security problems.
MIT