PostgREST: Auto-Generated API
PostgREST exposes PostgreSQL schemas directly as REST APIs.
Pigsty provides the app/postgrest template as a Pigsty CMDB API example using the read-only dbuser_view role. It publishes port 8884 on all host interfaces by default. Restrict it to loopback as shown below before starting.
Quick Start
Replace the postgrest service’s port mapping with:
Then run make up. After this change:
- 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_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. A JWT secret alone does not disable anonymous access: POSTGREST_DB_ANON_ROLE still determines database privileges for unauthenticated requests. Start with make up to apply Compose settings; make run is a separate docker run command and does not use the port mapping above.
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
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)