postgrest is a free, open source databases project written in Haskell and released under MIT. It has 27,670 GitHub stars, 1,229 forks and 400 open issues, and was last pushed 4 hours ago. On this registry it ranks #19 of 81 tracked projects in Databases, with 5 head-to-head comparisons available. It gained 2 stars over the last 3 tracked days.

What is postgrest?

PostgREST is a Haskell-written server that serves a fully RESTful API from any existing PostgreSQL database, and it is aimed at developers, database administrators, and operators who want a standards-compliant HTTP API without writing and maintaining one from scratch.

What it is

PostgREST is a standalone HTTP server, written in Haskell with the Warp HTTP server, that exposes an existing PostgreSQL database as a RESTful API. It uses the Hasql library to keep a pool of database connections, speak the PostgreSQL binary protocol, and remain stateless so the server can scale horizontally. Authentication is handled via JSON Web Tokens, and authorization is delegated to role information defined inside the database. The server assumes the identity of the authenticated user for the duration of the connection, so it cannot do anything that user could not do. Versioning is performed through database schemas, and OpenAPI output provides self-documentation that tools such as Swagger-UI can render.

The concrete problem it solves is the custom API layer that teams otherwise write, maintain, and secure by hand. Rather than relying on an Object Relational Mapper and custom imperative coding, PostgREST requires declarative constraints directly in the database and delegates as much calculation as possible to PostgreSQL: serializing JSON responses in SQL, validating data, enforcing authorization, combining row counting and retrieval, and posting data in a single command with returning *. The README describes the result as a cleaner, more standards-compliant, faster API than one written from scratch. It lives in the PostgreSQL ecosystem and replaces the hand-written REST API and ORM-centric data access layer that would otherwise sit between a database and its clients.

Key capabilities

  • Serves a fully RESTful API from any existing PostgreSQL database without application server code.
  • Authenticates with JSON Web Tokens (JWT) and delegates authorization to role information defined in the database.
  • Generates OpenAPI documentation for the live API, which can be rendered with Swagger-UI.
  • Reports and limits the number of rows returned by an endpoint through range headers.
  • Versions APIs through database schemas, allowing tables and views to be exposed while underlying tables are hidden behind public-facing views.
  • Delegates JSON serialization, data validation, authorization, combined row counting and retrieval, and data post in a single command (returning *) to SQL.
  • Uses Hasql with a database connection pool, the PostgreSQL binary protocol, and a stateless design for horizontal scaling.

Who uses it and how

  • Teams that already run PostgreSQL and need an HTTP API over existing tables and views, without writing and maintaining separate API code.
  • Operators deploying the server on a supported platform or through the Docker image postgrest/postgrest.
  • Applications that need JWT-based authentication while keeping authorization rules in PostgreSQL roles.
  • Developers who want interactive, always-current API documentation through OpenAPI and Swagger-UI.
  • Self-hosters and horizontally scaled deployments; the README reports subsecond response times for up to 2000 requests per second on the Heroku free tier.

Getting started

Install PostgREST on your platform according to the documentation at postgrest.org, or use the Docker image postgrest/postgrest; the Hackage package is postgrest, and postgrest --help prints invocation help.

How it compares

The facts name no comparable tools or paid products that PostgREST replaces. It stands alone in this registry.

When to use it — and when not to

Choose PostgREST when PostgreSQL is the source of truth and when security, versioning, and validation can live in database roles, schemas, views, and declarative constraints. A self-hoster must operate PostgreSQL and provide JWT-based authentication; the README does not mention SMTP, object storage, or other external services. Skip it when the application needs imperative server-side logic, an Object Relational Mapper, or authorization and integrity rules outside the database, and note that the repository carries 400 open issues.

project readme (upstream, from github) — read inline

Logo

Donate Docs Docker Stars Build Status Coverage Status Hackage docs

PostgREST serves a fully RESTful API from any existing PostgreSQL database. It provides a cleaner, more standards-compliant, faster API than you are likely to write from scratch.

Sponsors

Big thanks to our sponsors! You can join them by supporting PostgREST on Patreon.

Usage

  1. See the docs for how to install PostgREST on your platform. You can also use Docker.

  2. Invoke for help:

    postgrest --help
    

Documentation

Latest documentation is at postgrest.org. You can contribute to the docs in PostgREST/postgrest/docs.

Performance

TLDR; subsecond response times for up to 2000 requests/sec on Heroku free tier. If you're used to servers written in interpreted languages, prepare to be pleasantly surprised by PostgREST performance.

Three factors contribute to the speed. First the server is written in Haskell using the Warp HTTP server (aka a compiled language with lightweight threads). Next it delegates as much calculation as possible to the database including

Finally it uses the database efficiently with the Hasql library by

Security

PostgREST handles authentication (via JSON Web Tokens) and delegates authorization to the role information defined in the database. This ensures there is a single declarative source of truth for security. When dealing with the database the server assumes the identity of the currently authenticated user, and for the duration of the connection cannot do anything the user themselves couldn't. Other forms of authentication can be built on top of the JWT primitive. See the docs for more information.

Versioning

A robust long-lived API needs the freedom to exist in multiple versions. PostgREST does versioning through database schemas. This allows you to expose tables and views without making the app brittle. Underlying tables can be superseded and hidden behind public facing views.

Self-documentation

PostgREST uses the OpenAPI standard to generate up-to-date documentation for APIs. You can use a tool like Swagger-UI to render interactive documentation for demo requests against the live API server.

This project uses HTTP to communicate other metadata as well. For instance the number of rows returned by an endpoint is reported by - and limited with - range headers. More about that.

Data Integrity

Rather than relying on an Object Relational Mapper and custom imperative coding, this system requires you to put declarative constraints directly into your database. Hence no application can corrupt your data (including your API server).

The PostgREST exposes HTTP interface with safeguards to prevent surprises, such as enforcing idempotent PUT requests.

See examples of PostgreSQL constraints and the API guide.

Supporting development

You can help PostgREST ongoing maintenance and development by making a regular donation through Patreon https://www.patreon.com/postgrest

Every donation will be spent on making PostgREST better for the whole community.

Contributing

Contributions are always welcome and appreciated. Please see the Contributing guidelines.

Thanks

The PostgREST organization is grateful to:

The cool logo came from Mikey Casalaina.

Frequently asked questions

Is postgrest free to use?

postgrest is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does postgrest do?

REST API for any Postgres database

What is postgrest written in?

postgrest is primarily written in Haskell. Its source is publicly available at https://github.com/PostgREST/postgrest, and it has 27,670 GitHub stars.