Skip to content
Beau Barker edited this page Oct 7, 2025 · 30 revisions

PostgREST is a standalone web server that automatically transforms a PostgreSQL database into a RESTful API. It eliminates the need to write manual backend code for CRUD (Create, Read, Update, Delete) operations by leveraging the database's existing structure, constraints, and permissions to define API endpoints and their behavior.

1. Start PostgreSQL

Either use a managed service or self-host PostgreSQL.

2. Add PostgREST Service

Add a PostgREST service to your application:

app/compose.yaml

  postgrest:
    image: postgrest/postgrest:v12.2.8
    environment:
      PGRST_DB_ANON_ROLE: anon
      PGRST_DB_URI: postgres://authenticator:${PGRST_AUTHENTICATOR_PASS:?}@postgres:5432/app

If you're self-hosting PostgreSQL, be sure to also connect to the database's network:

app/compose.yaml

services:
  postgrest:
    networks:
      - default
      - db_default

networks:
  db_default:
    external: true

Optionally in development, increase the log level:

app/compose.override.yaml

  postgrest:
    environment:
      PGRST_LOG_LEVEL: debug

2. Add Routes

app/caddy/Caddyfile

# PostgREST
handle_path /rest/* {
  reverse_proxy http://postgrest:3000
}

handle /rpc/* {
  reverse_proxy http://postgrest:3000
}

Clone this wiki locally