postgrest 0,0,1,1,21,5,4,4 docker circleci

REST API for any Postgres database

2 years after MIT

Logo

Build Status

Deploy

Join the chat at https://gitter.im/begriffs/postgrest 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.

Usage

  1. Download the binary (latest release) for your platform.
  2. Invoke for help:

    postgrest --help

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 (or named after precious gems), 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

  • Serializing JSON responses directly in SQL
  • Data validation
  • Authorization
  • Combined row counting and retrieval
  • Data post in single command (returning *)

Finally it uses the database efficiently with the Hasql library by

  • Keeping a pool of db connections
  • Using the PostgreSQL binary protocol
  • Being stateless to allow horizontal scaling

Other optimizations are possible, and some are outlined in the Future Features.

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.

PostgreSQL 9.5 supports true row-level security. In previous versions it can be simulated with triggers and security-barrier views. Because the possible queries to the database are limited to certain templates using leakproof functions, the trigger workaround does not compromise row-level security.

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 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.

Thanks

I'm grateful to the generous project contributors who have improved PostgREST immensely with their code and good judgement. See more details in the changelog.

The cool logo came from Mikey Casalaina.

Related Repositories

catarse

catarse

The first open source crowdfunding platform for creative projects in the world ...

postgrest-starter-kit

postgrest-starter-kit

Boilerplate and tooling for authoring REST API backends with PostgREST ...

mithril-postgrest

mithril-postgrest

A mithril plugin to autenticate requests ...

postgrest-docs

postgrest-docs

Documentation for ...

simple-rest-api

simple-rest-api

A simple RESTful API in three easy steps. ...


Top Contributors

begriffs ruslantalpa diogob adambaker calebmer hudayou davidthewatson jcristovao motiz88 Recmo sscarduzio league rall brikou daurnimator bobcolner bgamari eric-brechemier framp fike mkhon edofic chrishepner rowdypixel dbc60 edelans ehamberg guido4000 manufaktor xDAGRONx

Releases

-   v0.3.2.0 zip tar
-   v0.3.1.1 zip tar
-   v0.3.1.0 zip tar
-   v0.3.0.4 zip tar
-   v0.3.0.3 zip tar
-   v0.3.0.2 zip tar
-   v0.3.0.1 zip tar
-   v0.3.0.0 zip tar
-   v0.2.12.1 zip tar
-   v0.2.12.0 zip tar
-   v0.2.11.1 zip tar
-   v0.2.11.0 zip tar
-   v0.2.10.0 zip tar
-   v0.2.9.1 zip tar
-   v0.2.9.0 zip tar
-   v0.2.8.0 zip tar
-   v0.2.7.0 zip tar
-   v0.2.6.0 zip tar
-   v0.2.5.3 zip tar
-   v0.2.5.2 zip tar
-   v0.2.5.1 zip tar
-   v0.2.5.0 zip tar
-   v0.2.4.10 zip tar
-   v0.2.4.9 zip tar
-   v0.2.4.8 zip tar
-   v0.2.4.7 zip tar
-   v0.2.2.1 zip tar
-   v0.1.0.0 zip tar