---
title: "Deploy PostgREST"
description: "Turn your PostgreSQL database into a RESTful API"
category: "Other"
url: https://railway.com/deploy/0cbz2v
---

# Deploy PostgREST

Turn your PostgreSQL database into a RESTful API

**[Deploy PostgREST on Railway](https://railway.com/template/0cbz2v)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/0cbz2v/manifest.json

- **Creator:** kovalromank's Projects
- **Category:** Other
- **Total deploys:** 9

## Template content

### postgrest/postgrest https://avatars.githubusercontent.com/u/15115011?s=200&v=4

- **Image:** postgrest/postgrest
- **Public domain:** Yes

## Documentation

Simple template to deploy a PostgREST service.

Set the `PGRST_DB_URI` variables to your Postgres connection string or reference, for example `${{Postgres.DATABASE_PRIVATE_URL}}`.

**Example on how to get a basic working service running (copied from the [PostgREST documentation](https://docs.postgrest.org/en/stable/tutorials/tut0.html)):**

Create a schema for database objects that will be exposed in our API:

```sql
create schema api;
```

Create a `todos` table:

```sql
create table api.todos (
  id int primary key generated by default as identity,
  done boolean not null default false,
  task text not null,
  due timestamptz
);

insert into api.todos (task) values
  ('finish tutorial 0'), ('pat self on back');
```

Make a role to use for anonymous web requests:

```sql
create role web_anon nologin;

grant usage on schema api to web_anon;
grant select on api.todos to web_anon;
```

Set the `PGRST_DB_SCHEMAS` variable to `api` (the schema you created).

Set the `PGRST_DB_ANON_ROLE` variable to `web_anon` (the role we created).

Deploy the service and visit your service's HTTP endpoint at `/todos` to view your todos.

Because the role we created only grants `select` access on the `api.todos` table, anonymous users will not be able to modify the table.

**Authentication**

To authenticate users with the API generate a JWT secret and set the `PGRST_JWT_SECRET` variable.

For example with OpenSSL:

```sh
openssl rand -base64 32
```

Store the output in the `PGRST_JWT_SECRET` variable and set the `PGRST_JWT_SECRET_IS_BASE64` to `true`.

Follow the [PostgREST tutorial](https://docs.postgrest.org/en/stable/tutorials/tut1.html#tut1) on how to use this secret to enable authentication for a user.

## Similar templates

- [Rocky Linux](https://railway.com/deploy/rocky-linux) — Hosted Rocky Linux 9 workspace with SSH and persistent storage. 🚀
- [Foundry Virtual Tabletop](https://railway.com/deploy/X5tR6G) — A Self-Hosted & Modern Roleplaying Platform
- [Letta Code Remote](https://railway.com/deploy/letta-code-remote) — Run a Letta Code agent 24/7. No inbound ports, just deploy.

Open this page in a browser: https://railway.com/deploy/0cbz2v
