PostgREST is a standalone web server that exposes tables and views in PostgreSQL as a REST API. Database schemas, constraints, and role permissions define available endpoints and access rules.
Overview
PostgREST turns an existing PostgreSQL database into a RESTful HTTP API without hand-written CRUD application code. Endpoints and allowed operations come from the database structure—schemas, views, constraints, and PostgreSQL roles—so authorization and validation can stay declared in the database rather than duplicated in application layers.
The server is written in Haskell and uses a connection pool with PostgreSQL’s binary protocol. Much work is pushed into the database, including JSON serialization in SQL, combined row counting and retrieval, and JWT-based authentication with authorization enforced through database roles.
API versioning is handled through database schemas, allowing public views to hide evolving underlying tables. OpenAPI documentation can be generated from the live API, and HTTP range headers report and limit row counts. PUT requests are constrained to be idempotent.
You install PostgREST on your platform or run it via Docker and point it at PostgreSQL. It is designed to sit behind tools such as Nginx and to scale horizontally as a stateless service. Integrations mentioned in the ecosystem include PostGIS, pg-safeupdate, systemd, and NixOS deployments.
Key features
- Auto-generated REST endpoints from PostgreSQL
- JWT authentication with database role delegation
- OpenAPI self-documentation
- Schema-based API versioning
- Connection pooling via Hasql
- Row count and limit via HTTP ranges
- Idempotent PUT safeguards
- Docker and platform install options
Use cases
- Rapid APIs over existing Postgres schemas
- Microservices with SQL-centric business logic
- Replacing custom CRUD API servers
- Exposing read/write data behind Nginx
- Horizontally scaled stateless data APIs