## 前提条件
- [[Ubuntu]] ([[WSL]])
- [[PostgreSQL]]がインストール済、かつdbデータベースとusersテーブル作成済
- バージョンは14.10
## インストール
[[Docker]]を使う。
<div class="link-card">
<div class="link-card-header">
<img src="https://postgrest.org/en/latest/_static/favicon.ico" class="link-card-site-icon"/>
<span class="link-card-site-name">PostgREST</span>
</div>
<div class="link-card-body">
<div class="link-card-content">
<p class="link-card-title">Installation</p>
<p class="link-card-description">The release page has pre-compiled binaries for macOS, Windows, Linux and FreeBSD. ...</p>
</div>
<img src="https://postgrest.org/en/latest/_images/win-err-dialog.png" class="link-card-image" />
</div>
<a href="https://postgrest.org/en/latest/explanations/install.html#docker"></a>
</div>
```console
docker pull postgrest/postgrest
```
## 起動
```console
docker run --rm --net=host \
-e PGRST_DB_URI="postgres://app_user:password@localhost/db" \
postgrest/postgrest
```
## 実行
認証が必要そう?
```bash
$ curl http://localhost:3000/users
{"code":"PGRST302","details":null,"hint":null,"message":"Anonymous access is disabled"}
```
## 対応
SCHEMAと`ANON_ROLE`を設定することで解消。
```console
docker run --rm --net=host \
-e PGRST_DB_URI="postgres://app_user:password@localhost/db" \
-e PGRST_DB_SCHEMA="api" \
-e PGRST_DB_ANON_ROLE="web_anon" \
postgrest/postgrest
```
> [!info] 設定ファイルを指定する方法もありそう
> `postgrest.conf`を作成して指定するとよさそう。
>
> https://postgrest.org/en/latest/references/configuration.html#config-file
>
> ```
> db-uri = "postgres://app_user:password@localhost/db"
> db-schemas = "api"
> db-anon-role = "web_anon"
> ```
>