NpgsqlRest 3.21.0

dotnet add package NpgsqlRest --version 3.21.0
                    
NuGet\Install-Package NpgsqlRest -Version 3.21.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NpgsqlRest" Version="3.21.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NpgsqlRest" Version="3.21.0" />
                    
Directory.Packages.props
<PackageReference Include="NpgsqlRest" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NpgsqlRest --version 3.21.0
                    
#r "nuget: NpgsqlRest, 3.21.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NpgsqlRest@3.21.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NpgsqlRest&version=3.21.0
                    
Install as a Cake Addin
#tool nuget:?package=NpgsqlRest&version=3.21.0
                    
Install as a Cake Tool

NpgsqlRest

Build, Test, Publish and Release Tests 2400+ integration tests License Sponsor GitHub Stars GitHub Forks

Your SQL is the API

Automatic REST API for PostgreSQL | 6.1x faster than PostgREST

SQL files and PostgreSQL objects become REST endpoints. TypeScript 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

"Simplicity is the ultimate sophistication." — Leonardo da Vinci

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.

Install

Method Command
NPM npm i 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 for all options and details.

From SQL to REST API

Write a SQL file:

-- 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"}]}

And a generated TypeScript client with full type safety:

interface IProcessOrderResponse {
    validate: number;
    result2: number;
    confirm: { id: number, status: string }[];
}

export async function processOrder(
    request: IProcessOrderRequest
) : Promise<ApiResult<IProcessOrderResponse>> {
    const response = await fetch(baseUrl + "/api/process-order", {
        method: "POST",
        body: JSON.stringify(request)
    });
    return {
        status: response.status,
        response: response.ok ? await response.json() as IProcessOrderResponse : undefined!,
        error: !response.ok && response.headers.get("content-length") !== "0" ? await response.json() as ApiError : undefined
    };
}

No framework, no ORM, no boilerplate. The named placeholder :order_id — used three times, bound once — is the API parameter, and every result key is typed, down to the @single scalar and the column shapes. ApiResult<T> carries the status and a typed error, so failures are type-safe too.

Endpoint Sources

Source What it's good for Example
SQL Files (recommended starting point) Simple queries, multi-command batch scripts, no DB deployment needed sql/get_users.sqlGET /api/get-users
Functions & Procedures Full PL/pgSQL power, static type checking, reusable logic get_user_by_id(int)GET /api/get-user-by-id

SQL files are the easiest way to get started — drop a .sql file in a folder and you have an endpoint. Functions give you the full power of PL/pgSQL with true end-to-end type checking. Use both together, or whichever fits.

All sources share the same annotation system: @authorize, @param, @returns, @void, @single, @cached, @path, and 50+ others.

Declarative Annotations

Declare what you want from your endpoint — caching, authorization, timeouts, retries, rate limiting, output format — right where the SQL lives:

/*
HTTP GET /users/
@authorize admin, user
@cached
@cache_expires_in 30sec
@timeout 5min
@table_format = excel
@excel_file_name = users.xlsx
*/
select id, name, email, role
from users
where $1 is null or department_id = $1;

Same pattern for PostgreSQL functions via comment on function ... is '...'. No middleware to register, no decorators, no controllers — the SQL is the source of truth. See all annotations.

Tests Are SQL Files Too

No test framework, no running server, no mocks. npgsqlrest --test invokes the real endpoint pipeline in-process, on the test's own transaction — insert fixtures, call the endpoint (it sees your uncommitted rows), assert with SQL, roll back:

-- tests/get_users.test.sql
begin;

insert into users (email) values ('fixture@example.com');

/*
GET /api/get-users
# @claim user_id=1
*/
select status = 200, 'authenticated caller gets 200' from _response;
select body::jsonb @> '[{"email": "fixture@example.com"}]', 'fixture is listed' from _response;

rollback;
npgsqlrest ./config.json --test

PASS  tests/get_users.test.sql  (2 assertions, 52ms)
19 passed, 0 failed, 0 error(s)  —  19 assertions in 9 files
endpoint coverage: 2/2 (100%)

Parallel isolated connections, throwaway test databases (create database app_test_{rnd5} as a plain setup step), per-test database clones, tags, JUnit XML, and endpoint coverage with a CI threshold gate — Testing Guide.

Watch Mode

npgsqlrest ./config.json --watch

Save a .sql file and the running API restarts with the change (~1s). create or replace a function in psql and the endpoint is live seconds later — the database itself is watched, annotations included. The TypeScript client regenerates every cycle, so your frontend types follow your SQL as you type. Add --test and it becomes a millisecond test loop instead — a changed test re-runs alone; a changed endpoint rebuilds in-process. Watch Mode.

Features

  • Multi-command SQL scripts — multiple statements in one file execute as a batch, returning named result sets
  • Named parameters in SQL fileswhere email = :email; the placeholder is the API parameter, repeated names bind once
  • SQL test runner (--test) — tests as plain SQL files, in-process endpoint invocation inside the test's transaction, throwaway test databases, JUnit XML, endpoint-coverage gating
  • Watch mode (--watch) — restart on SQL file, configuration, and database routine changes; test watch re-runs in milliseconds
  • MCP server@mcp exposes any endpoint as a Model Context Protocol tool for AI agents, same auth and rate limits
  • AI function-calling schemas & llms.txt — project the MCP tool set into OpenAI and Anthropic tools array documents plus an llms.txt capability document, generated and served even without the /mcp endpoint
  • TypeScript/JS code generation and .http files — types flow from PostgreSQL to your frontend, with optional TanStack Query (React Query) v5 hooks (useQuery/useMutation + query-key factories)
  • Dart client generation — typed Flutter clients on package:http: request/response models with fromJson/toJson, multipart uploads with progress, SSE subscriptions, MockClient testability
  • AOT-compiled native binaries — zero dependencies, instant startup
  • 6.1x faster than PostgREST at 100 concurrent users
  • 50+ comment annotations@authorize, @param, @returns, @void, @single, @result, @skip, @cached, @proxy, and more
  • Auth — cookie auth, Basic auth, JWT claims, role-based access, @authorize, @allow_anonymous
  • Column-level encryption, security-sensitive endpoints, IP address binding
  • Response caching with per-endpoint expiration control
  • Rate limiting per endpoint
  • SSE streaming via RAISE INFO/NOTICE with graceful shutdown
  • HTTP QUERY method — the standardized safe method with a request body; parameters bind from the JSON body, clients treat it as a cacheable read
  • File uploads — large objects, file system, MIME filtering
  • Reverse proxy — forward to upstream services, transform proxy responses
  • HTTP custom types — PostgreSQL composite types that call external APIs and return structured responses
  • Composite type support — nested JSON, arrays of composites, @returns to skip Describe
  • OpenAPI 3.0 / 3.1 spec generation (configurable SpecVersion)
  • CSV/Excel/HTML table format response handlers

How does it compare?

NpgsqlRest vs PostgREST vs Supabase

From the Blog

Documentation

npgsqlrest.github.io — getting started, configuration, annotations, examples.

Claude Code skill

A Claude Code skill that teaches the agent how to build with NpgsqlRest — both endpoint sources (database functions/procedures/tables/views and .sql files), the full annotation set, configuration, HTTP custom types, proxy, caching, auth, SSE, MCP, client code generation (TypeScript/React Query hooks, Dart), the SQL test runner (--test), and watch mode (--watch). It lives in .claude/skills/npgsqlrest/ and bundles a complete annotation reference and a full annotated appsettings.json.

Install it for your own NpgsqlRest projects — per-user (available everywhere):

mkdir -p "$HOME/.claude/skills/npgsqlrest"
for f in SKILL.md annotations-reference.md configuration-reference.jsonc; do
  curl -fsSL "https://raw.githubusercontent.com/NpgsqlRest/NpgsqlRest/master/.claude/skills/npgsqlrest/$f" \
    -o "$HOME/.claude/skills/npgsqlrest/$f"
done

…or scope it to a single project by copying those three files into <your-project>/.claude/skills/npgsqlrest/. The agent then loads it automatically when you work on NpgsqlRest SQL, annotations, or config. The two reference files are generated from npgsqlrest --annotations and npgsqlrest --config; regenerate them with those commands if your installed version differs.

About

NpgsqlRest is built and maintained by Vedran Bilopavlović. The C# library, parser, codegen, and runtime are hand-written, covered by 2,484 integration tests, and battle-tested in production.

Support This Project ❤️

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.

Contributing

Contributions are welcome — see CONTRIBUTING.md for how to build, run the tests, and what a good PR looks like. Small, well-scoped issues are labeled good-first-issue.

Security

Please report vulnerabilities privately via GitHub Private Vulnerability Reporting — see SECURITY.md. Do not open public issues for security problems.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on NpgsqlRest:

Package Downloads
NpgsqlRest.TsClient

Automatic Typescript Client Code Generation for NpgsqlRest

NpgsqlRest.HttpFiles

Automatic HTTP Files Generation for NpgsqlRest

NpgsqlRest.CrudSource

CRUD Source for NpgsqlRest

NpgsqlRest.OpenAPI

Automatic HTTP Files Generation for NpgsqlRest

NpgsqlRest.SqlFileSource

SQL File Source for NpgsqlRest - generates REST API endpoints from .sql files

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.21.0 0 7/12/2026
3.20.0 60 7/9/2026
3.19.0 103 7/3/2026
3.18.2 142 6/26/2026
3.18.1 106 6/23/2026
3.18.0 110 6/23/2026
3.17.0 161 6/13/2026
3.16.2 108 6/2/2026
3.16.1 111 6/1/2026
3.16.0 106 5/20/2026
3.15.0 134 5/11/2026
3.14.0 113 5/9/2026
3.13.0 130 5/1/2026
3.12.0 150 4/2/2026
3.11.1 137 3/13/2026
3.11.0 139 3/10/2026
3.10.0 135 2/25/2026
3.8.0 219 2/11/2026
3.7.0 154 2/7/2026
3.6.2 129 2/2/2026
Loading failed