# `PgRest.Plug`
[🔗](https://github.com/agoodway/pgrest/blob/v0.1.0/lib/pg_rest/plug.ex#L1)

Phoenix Plug that routes requests to PgRest resources.

## Usage

    # In your router:
    forward "/api", PgRest.Plug, repo: MyApp.Repo

## Options

- `:repo` (required) - The Ecto repo module
- `:json` - JSON encoder/decoder module (default: `Jason`)
- `:max_limit` - Maximum rows per request, like PostgREST's `db-max-rows` (default: `nil` = no limit)
- `:context_builder` - A 2-arity function `(conn, opts) -> context_map` for custom context building

# `call`

```elixir
@spec call(Plug.Conn.t(), map()) :: Plug.Conn.t()
```

Routes incoming requests to the appropriate resource handler.

Matches `/:resource` and `/:resource/:id` paths, resolving the resource
via `PgRest.Registry` and dispatching to the correct CRUD operation.

# `init`

```elixir
@spec init(keyword()) :: map()
```

Initializes plug options.

Requires `:repo`. Optional: `:json` (default `Jason`), `:max_limit`,
`:context_builder`, `:authorization`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
