PostgREST: Auto-Generated API
Deploy PostgREST with Pigsty Compose templates and auto-generate REST APIs from PostgreSQL schema.
PostgREST exposes PostgreSQL schemas directly as REST APIs.
Pigsty’s app/postgrest template exposes a sample Pigsty CMDB API through the read-only dbuser_view user. Compose binds POSTGREST_SERVER_PORT (default 8884) to host loopback 127.0.0.1 only.
Quick Start
Default endpoint:
- Direct endpoint:
http://127.0.0.1:8884 - For remote access, use an SSH tunnel or an authenticated Nginx portal at
http://api.pigsty
Key Settings
Common .env parameters:
POSTGREST_SERVER_PORT: service listening port and loopback mapping port, default8884POSTGREST_DB_URI: database connection stringPOSTGREST_DB_SCHEMA: exposed schema (defaultpigsty)POSTGREST_DB_ANON_ROLE: anonymous rolePOSTGREST_JWT_SECRET: JWT secret
Set POSTGREST_JWT_SECRET to a random value of at least 32 characters. Setting a JWT secret alone does not disable anonymous access; POSTGREST_DB_ANON_ROLE still determines permissions for unauthenticated requests. make run is an alias for make up and uses the same Compose loopback binding.
Swagger UI (Optional)
You can run Swagger UI separately to preview APIs:
Open http://127.0.0.1:8883. If the services run on a remote host, forward both ports first:
Common Commands
References
- PostgREST docs: https://postgrest.org/en/stable/
- Pigsty template: https://github.com/pgsty/pigsty/tree/main/app/postgrest