{"id":13478903,"url":"https://github.com/PostgREST/postgrest-heroku","last_synced_at":"2025-03-27T08:31:07.211Z","repository":{"id":21475934,"uuid":"24794555","full_name":"PostgREST/postgrest-heroku","owner":"PostgREST","description":"Restful API on Heroku","archived":true,"fork":false,"pushed_at":"2022-11-02T17:22:57.000Z","size":45,"stargazers_count":61,"open_issues_count":2,"forks_count":57,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-10-30T12:48:22.650Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PostgREST.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-04T16:21:52.000Z","updated_at":"2024-08-23T21:56:36.000Z","dependencies_parsed_at":"2023-01-13T21:29:59.305Z","dependency_job_id":null,"html_url":"https://github.com/PostgREST/postgrest-heroku","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostgREST%2Fpostgrest-heroku","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostgREST%2Fpostgrest-heroku/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostgREST%2Fpostgrest-heroku/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostgREST%2Fpostgrest-heroku/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PostgREST","download_url":"https://codeload.github.com/PostgREST/postgrest-heroku/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245809770,"owners_count":20676048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T16:02:05.543Z","updated_at":"2025-03-27T08:31:06.913Z","avatar_url":"https://github.com/PostgREST.png","language":"Shell","funding_links":[],"categories":["Shell","others"],"sub_categories":[],"readme":"## PostgREST on Heroku\n\nThe best way to build an API, now for Heroku. Updated for PostgREST \u003e= v9.0.0\n\n**Free and hobby Heroku PostgreSQL add-on** do not support having multiple database roles (e.g. read-only or read-write roles). \n\n**Heroku Postgres paid tiers** do\nsupport multiple database roles, though you'll have to create them through\n[Heroku Postgres\nCredentials](https://devcenter.heroku.com/articles/heroku-postgresql-credentials) as explained below.\n\n### To Deploy PostgREST on Heroku\n\n1.  Log into Heroku using the [Heroku\n    CLI](https://devcenter.heroku.com/articles/heroku-cli):\n\n    ```bash\n    # If you have multiple Heroku accounts, use flag '--interactive' to switch between them\n    heroku login --interactive\n    ```\n\n2.  Create a new Heroku app using this Heroku buildpack:\n\n    ```bash\n    mkdir ${YOUR_APP_NAME}\n    cd ${YOUR_APP_NAME}\n    git init .\n\n    heroku apps:create ${YOUR_APP_NAME} --buildpack https://github.com/PostgREST/postgrest-heroku.git\n    heroku git:remote -a ${YOUR_APP_NAME}\n    ```\n\n3.  Create a new Heroku Postgres add-on attached to the app and keep notes of the assigned add-on name (e.g. postgresql-curly-58902) referred later as ${HEROKU_PG_DB_NAME}\n    ```bash\n    heroku addons:create heroku-postgresql:standard-0 -a ${YOUR_APP_NAME}\n    # wait until the add-on is available\n    heroku pg:wait -a ${YOUR_APP_NAME}\n    ```\n\n4.  Create the necessary user roles according to the \n    [PostgREST documentation](https://postgrest.org/en/stable/auth.html):\n\n    ```bash\n    heroku pg:credentials:create --name api_user -a ${YOUR_APP_NAME}\n    # use the following command to ensure the new credential state is active before attaching it\n    heroku pg:credentials -a ${YOUR_APP_NAME}\n\n    heroku addons:attach ${HEROKU_PG_DB_NAME} --credential api_user -a ${YOUR_APP_NAME}\n    ```\n\n5.  Connect to the Postgres database and create some sample data:\n\n    ```bash\n    heroku psql -a ${YOUR_APP_NAME}\n    ```\n\n    ```sql\n    # from the psql command prompt execute the following commands:\n    create schema api;\n\n    create table api.todos (\n    id serial primary key,\n    done boolean not null default false,\n    task text not null,\n    due timestamptz\n    );\n\n    insert into api.todos (task) values\n    ('finish tutorial 0'), ('pat self on back');\n\n    grant usage on schema api to api_user;\n    grant select on api.todos to api_user;\n    ```\n\n5.  Create the `Procfile`:\n\n    ```bash\n    web: PGRST_SERVER_HOST=0.0.0.0 PGRST_SERVER_PORT=${PORT} PGRST_DB_URI=${PGRST_DB_URI:-${DATABASE_URL}} ./postgrest-${POSTGREST_VER}\n    ```\n    Set the following environment variables on Heroku:\n    ```\n    heroku config:set POSTGREST_VER=10.0.0\n    heroku config:set PGRST_DB_SCHEMA=api\n    heroku config:set PGRST_DB_ANON_ROLE=api_user\n    ```\n\n    PGRST_DB_URI can be set if an external database is used or if it's different from the default Heroku DATABASE_URL. This latter is used if nothing is provided.  \n    POSTGREST_VER is mandatory to select and build the required PostgREST release.\n\n    See https://postgrest.org/en/stable/configuration.html#environment-variables for the full list of environment variables.\n\n6.  Build and deploy your app:\n\n    ```bash\n    git add Procfile\n    git commit -m \"PostgREST on Heroku\"\n    git push heroku master\n    ```\n\n    Your Heroku app should be live at `${YOUR_APP_NAME}.herokuapp.com`\n\n7.  Test your app\n\n    From a terminal display the application logs:\n    ```bash\n    heroku logs -t\n    ```\n    From a different terminal retrieve with curl the records previously created:\n    ```bash\n    curl https://${YOUR_APP_NAME}.herokuapp.com/todos\n    ```\n    and test that any attempt to modify the table via a read-only user is not allowed:\n    ```bash\n    curl https://${YOUR_APP_NAME}.herokuapp.com/todos -X POST \\\n     -H \"Content-Type: application/json\" \\\n     -d '{\"task\": \"do bad thing\"}'\n    ```    \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPostgREST%2Fpostgrest-heroku","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPostgREST%2Fpostgrest-heroku","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPostgREST%2Fpostgrest-heroku/lists"}