Installation

Installing from Pre-Built Release

The release page has precompiled binaries for Mac OS X and 64-bit Ubuntu. Next extract the tarball and run the binary inside with no arguments to see usage instructions:

$ tar zxf postgrest-0.2.11.1-osx.tar.xz
$ ./postgrest-0.2.11.1
Usage: postgrest-0.2.11.1 (-d|--db-name NAME) [-P|--db-port PORT]
                          (-U|--db-user ROLE) [--db-pass PASS] [--db-host HOST]
                          [-p|--port PORT] (-a|--anonymous ROLE) [-s|--secure]
                          [--db-pool COUNT] [--v1schema NAME]
                          [--jwt-secret SECRET]
  PostgREST 0.2.11.1 / create a REST API to an existing Postgres database

Available options:
  -h,--help                Show this help text
  -d,--db-name NAME        name of database
  -P,--db-port PORT        postgres server port (default: 5432)
  -U,--db-user ROLE        postgres authenticator role
  --db-pass PASS           password for authenticator role
  --db-host HOST           postgres server hostname (default: "localhost")
  -p,--port PORT           port number on which to run HTTP
                           server (default: 3000)
  -a,--anonymous ROLE      postgres role to use for non-authenticated requests
  -s,--secure              Redirect all requests to HTTPS
  --db-pool COUNT          Max connections in database pool (default: 10)
  --v1schema NAME          Schema to use for nonspecified version (or explicit
                           v1) (default: "1")
  --jwt-secret SECRET      Secret used to encrypt and decrypt JWT
                           tokens) (default: "secret")

We'll learn the meaning of the command line flags later, but here is a minimal example of running the app. It does all operations as user postgres, including for unauthenticated requests.

$ ./postgrest-0.2.11.1 -d dbname -U postgres --a postgres --v1schema public

Building from Source

When a prebuilt binary does not exist for your system you can build the project from source. You'll also need to do this if you want to help with development. Stack makes it easy. It will install any necessary Haskell dependencies on your system.

  1. Install Stack for your platform
  2. Build the project

     git clone https://github.com/begriffs/postgrest.git
     cd postgrest
     stack build
    
  3. Run the server

     stack exec postgrest -- arg1 arg2
     # ... your arguments after the double dashes
    

If you want to run the test suite, stack can do that too: stack test.

Installing PostgreSQL

To use PostgREST you will need an underlying database. You can use something like Amazon RDS but installing your own locally is cheaper and more convenient for development.