PgRest.BodyReader (PgRest v0.2.0)

Copy Markdown View Source

A Plug.Parsers body reader that keeps the raw request body.

plug Plug.Parsers,
  parsers: [:json],
  json_decoder: Jason,
  body_reader: {PgRest.BodyReader, :read_body, []}

The bytes accumulate in conn.private[:pgrest_raw_body]. PgRest.Request uses them when present, which lets writes pass the original JSON to Postgres instead of re-encoding the decoded payload.

Summary

Functions

Delegates to Plug.Conn.read_body/2, caching every chunk read.

Functions

read_body(conn, opts)

@spec read_body(Plug.Conn.t(), keyword()) ::
  {:ok, binary(), Plug.Conn.t()}
  | {:more, binary(), Plug.Conn.t()}
  | {:error, term()}

Delegates to Plug.Conn.read_body/2, caching every chunk read.