Skip to content

NpgsqlRestAutomatic PostgreSQL Web Server

SQL is declarative โ€” your API should be too. Write SQL, annotate it with comments to declare caching, auth, retries, rate limiting, and everything in between. PostgreSQL is the architecture.

NpgsqlRest Architecture - PostgreSQL at the center with automatic REST API, TypeScript generation, authentication, caching, and more

PostgreSQL is the architecture โ€” not a detail to abstract away

  • โœ“ Declare, don't code โ€” Caching, auth, retries, rate limiting โ€” all declared as SQL annotations
  • โœ“ PostgreSQL at the center โ€” The opposite of Clean Architecture: the database drives everything
  • โœ“ Types flow outward โ€” PostgreSQL types generate TypeScript clients automatically
  • โœ“ No middle tier โ€” No controllers, no models, no mapping layers, no boilerplate

Declarative Annotations โ€‹

Declare what you want from your endpoint โ€” caching, authorization, timeouts, retries, rate limiting โ€” right where the SQL lives.

SQL File

sql
/*
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;

PostgreSQL Function

sql
create or replace function api.get_users(
  _department_id int
)
returns table (id int, name text, email text, role text)
language sql
begin atomic;
select id, name, email, role
from users
where
  _department_id is null
  or department_id = _department_id;
end;

comment on function api.get_users(int) is '
HTTP GET /users/
@authorize admin, user
@cached
@cache_expires_in 30sec
@timeout 10sec
@retry_strategy aggressive
@rate_limiter_policy authenticated_limit
@tsclient_module = users
';

Blog โ€‹


Build, Test, Publish and ReleaseLicenseGitHub StarsGitHub ForksCrafted with Claude
โค๏ธ Support this project: Patreon ยท Buy Me a Coffee
Released under the MIT License.
Copyright ยฉ 2024-2026 VB Consulting