Deploy PostgREST

PostgREST 16.3 instant REST API over Postgres with JWT auth and Swagger UI.

Deploy PostgREST

/var/lib/postgresql/data

Deploy and Host PostgREST on Railway

PostgREST turns a PostgreSQL database into a RESTful API. Tables, views and functions in the exposed schema become endpoints with filtering, pagination, embedding and OpenAPI docs. Permissions come from Postgres roles, grants and row-level security, and requests are authenticated with JWTs. It powers the REST layer of Supabase.

About Hosting PostgREST

This template deploys PostgREST v16.3, a Railway Postgres database and Swagger UI. On every start, a small wrapper creates the authenticator, web_anon and authenticated roles and the api schema, and it is safe to re-run. It also adds an event trigger so new tables appear in the API without a restart. Anonymous requests get nothing until you grant access. Requests carrying a JWT with "role": "authenticated", signed with the generated secret, can read and write tables in api. PostgREST is light and stateless, so the Hobby plan is enough for most projects.

Common Use Cases

  • An instant CRUD API for a frontend, mobile app or internal tool, backed by Postgres
  • Exposing SQL views and functions as endpoints without writing a backend
  • Row-level-security APIs where each JWT only sees its own rows

Dependencies for PostgREST Hosting

  • PostgREST v16.3 (official postgrest/postgrest:v16.3 binary, digest-pinned) built from aalfath/postgrest-railway-template
  • Railway Postgres (ghcr.io/railwayapp-templates/postgres-ssl:18) with a volume
  • swaggerapi/swagger-ui:v5.33.0 for interactive API docs

Deployment Dependencies

Implementation Details

ServiceSourceNetworkingStorage
postgrestrepo aalfath/postgrest-railway-templatepublic domain on 3000; private IPv4/IPv6none
docsswaggerapi/swagger-ui:v5.33.0public domain on 8080none
PostgresRailway Postgres 18private onlyvolume

Create a table (for example with psql against the Postgres service) and it is live immediately:

create table api.todos (id bigint generated always as identity primary key, task text not null, done boolean default false);

Call it with a JWT signed (HS256) with PGRST_JWT_SECRET, payload {"role": "authenticated"}:

curl https:///todos -H "Authorization: Bearer "
curl -X POST https:///todos -H "Authorization: Bearer " \
  -H "Content-Type: application/json" -d '{"task": "ship it"}'

To allow anonymous reads of a table: grant select on api.todos to web_anon;

VariableDefaultPurpose
PGRST_JWT_SECRETgenerated 64-character secretVerifies request JWTs
PGRST_AUTHENTICATOR_PASSWORDgenerated secretPassword of the low-privilege login role PostgREST uses
PGRST_DB_SCHEMASapiExposed schema(s)
PGRST_DB_ANON_ROLEweb_anonRole for requests without a JWT
DATABASE_URL${{Postgres.DATABASE_URL}}Owner connection, used only for the bootstrap

Notes:

  • Any PGRST_* setting from the PostgREST configuration reference can be added as a variable.
  • New tables in api are granted to authenticated automatically; use row-level security for per-user access.
  • Set PGRST_BOOTSTRAP=false to skip the role and schema setup and manage it yourself.

This is a community-maintained deployment package and does not imply affiliation with or endorsement by the PostgREST project.

Why Deploy PostgREST on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying PostgREST on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


Template Content

More templates in this category

View Template
open-excalidraw
Self-hostable collaborative drawing built on Excalidraw

Prateek Mohanty
3
View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

5
View Template
NEW
WireMock Private API Stubs
Persistent HTTP API stubs behind generated owner access.

orenaksakal
0