PgRest.Plug (PgRest v0.1.0)

Copy Markdown View Source

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

Summary

Functions

Routes incoming requests to the appropriate resource handler.

Initializes plug options.

Functions

call(conn, opts)

@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(opts)

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

Initializes plug options.

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