{"id":20073866,"url":"https://github.com/jimbrig/postgresql_rest_api","last_synced_at":"2026-05-31T21:32:12.181Z","repository":{"id":105150384,"uuid":"353849298","full_name":"jimbrig/postgresql_rest_api","owner":"jimbrig","description":"Setting up a REST API and PostgreSQL database sandbox.","archived":false,"fork":false,"pushed_at":"2024-02-29T20:26:18.000Z","size":15866,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T12:27:40.581Z","etag":null,"topics":["api","postgresql","postgrest","rest-api","sandbox","testing"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jimbrig.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-01T23:14:24.000Z","updated_at":"2021-06-23T22:45:26.000Z","dependencies_parsed_at":"2024-11-13T14:59:38.914Z","dependency_job_id":null,"html_url":"https://github.com/jimbrig/postgresql_rest_api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jimbrig/postgresql_rest_api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbrig%2Fpostgresql_rest_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbrig%2Fpostgresql_rest_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbrig%2Fpostgresql_rest_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbrig%2Fpostgresql_rest_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimbrig","download_url":"https://codeload.github.com/jimbrig/postgresql_rest_api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimbrig%2Fpostgresql_rest_api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33750474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api","postgresql","postgrest","rest-api","sandbox","testing"],"created_at":"2024-11-13T14:48:36.202Z","updated_at":"2026-05-31T21:32:12.166Z","avatar_url":"https://github.com/jimbrig.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostgreSQL + REST API + Application(s)\n\n- Setup a tutorial PostgreSQL database with docker:\n\n```bash\nsudo docker run --name pgdb -p 5433:5432 -e POSTGRES_PASSWORD=p -d postgres\n```\n\n## Install [PostgREST]()\n\n- Download `tar.xz` file from: https://github.com/PostgREST/postgrest/releases/latest\n\n```bash\ntar xJf postgrest-\u003cversion\u003e-\u003cplatform\u003e.tar.xz\n```\n\nLinux:\n\n```bash\n# un-compress into working directory\ntar xJf bin/postgrest-v7.0.1-linux-x64-static.tar.xz\n\n# run\n./postgrest\n\nMissing: FILENAME\n\nUsage: postgrest FILENAME\n  PostgREST 7.0.1 (UNKNOWN) / create a REST API to an existing Postgres database\n\nAvailable options:\n  -h,--help                Show this help text\n  FILENAME                 Path to configuration file\n\nExample Config File:\n  db-uri = \"postgres://user:pass@localhost:5432/dbname\"\n  db-schema = \"public\" # this schema gets added to the search_path of every request\n  db-anon-role = \"postgres\"\n  db-pool = 10\n  db-pool-timeout = 10\n\n  server-host = \"!4\"\n  server-port = 3000\n\n  ## unix socket location\n  ## if specified it takes precedence over server-port\n  # server-unix-socket = \"/tmp/pgrst.sock\"\n  ## unix socket file mode\n  ## when none is provided, 660 is applied by default\n  # server-unix-socket-mode = \"660\"\n\n  ## base url for swagger output\n  # openapi-server-proxy-uri = \"\"\n\n  ## choose a secret, JSON Web Key (or set) to enable JWT auth\n  ## (use \"@filename\" to load from separate file)\n  # jwt-secret = \"secret_with_at_least_32_characters\"\n  # secret-is-base64 = false\n  # jwt-aud = \"your_audience_claim\"\n\n  ## limit rows in response\n  # max-rows = 1000\n\n  ## stored proc to exec immediately after auth\n  # pre-request = \"stored_proc_name\"\n\n  ## jspath to the role claim key\n  # role-claim-key = \".role\"\n\n  ## extra schemas to add to the search_path of every request\n  # db-extra-search-path = \"extensions, util\"\n\n  ## stored proc that overrides the root \"/\" spec\n  ## it must be inside the db-schema\n  # root-spec = \"stored_proc_name\"\n\n  ## content types to produce raw output\n  # raw-media-types=\"image/png, image/jpg\"\n```\n\n## Requirements:\n\n- libpq\n- PostgrSQL C Library\n\n## Create a Database for API\n\n```\n# execute psql within docker\nsudo docker exec -it pgdb psql -U postgres\n\n# create api schema\npostgres=# create schema api;\n\n# create table for 'orders' endpoint:\npostgres=# create table api.orders (\npostgres(# id serial primary key,\npostgres(# order_type text not null default 'new',\npostgres(# order_status text not null default 'pending',\npostgres(# price real not null default 0,\npostgres(# datetime timestamptz not null default now() \npostgres(# );\n\n# add some values\ninsert into api.orders (order_type) values ('new'), ('swap');\n\n# create nologin role\ncreate role web_anon nologin;\ngrant usage on schema api to web_anon;\ngrant select on api.orders to web_anon;\n```\n\nThe `web_anon` role has permission to access things in the `api` schema, and to read rows in the `orders` table.\n\nIt’s a good practice to create a dedicated role for connecting to the database, instead of using the highly privileged `postgres` role. \n\nName the role `authenticator` and also grant him the ability to switch to the `web_anon` role :\n\n```\ncreate role authenticator noinherit login password 'p';\ngrant web_anon to authenticator;\n```\n\nNow quit out of psql; it’s time to start the API!\n\n```\n\\q\n```\n\n## Run PostgREST\n\nPostgREST uses a configuration file to tell it how to connect to the database. Create a file `tutorial.conf` with this inside:\n\n```\ndb-uri = \"postgres://authenticator:mysecretpassword@localhost:5433/postgres\"\ndb-schema = \"api\"\ndb-anon-role = \"web_anon\"\n```\n\nThe configuration file has other [options](https://postgrest.org/en/v7.0.0/configuration.html#configuration), but this is all we need. Now run the server:\n\n```\n./postgrest tutorial.conf\n```\n\nYou should see\n\n```\nListening on port 3000\nAttempting to connect to the database...\nConnection successful\n```\n\nIt’s now ready to serve web requests. There are many nice graphical API exploration tools you can use, but for this tutorial we’ll use `curl` because it’s likely to be installed on your system already. Open a new terminal (leaving the one open that PostgREST is running inside). Try doing an HTTP request for the todos.\n\n```\ncurl http://localhost:3000/orders\n```\n\nThe API replies:\n\n```\n[\n  {\n    \"id\": 1,\n    \"order_type\": \"new\",\n    \"order_status\": \"pending\",\n    \"price\": 0,\n    \"datetime\": null\n  },\n  {\n    \"id\": 2,\n    \"order_type\": \"swap\",\n    \"order_status\": \"pending\",\n    \"price\": 0,\n    \"datetime\": null\n  }\n]\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimbrig%2Fpostgresql_rest_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimbrig%2Fpostgresql_rest_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimbrig%2Fpostgresql_rest_api/lists"}