# `Unicom360.Webhook.BodyReader`
[🔗](https://github.com/TechRode-Solution-Limited/unicom360-elixir/blob/v0.1.0/lib/unicom360/webhook/body_reader.ex#L2)

A `Plug.Parsers` body reader that keeps the raw body in `conn.assigns.raw_body`.

Webhook signatures cover the exact bytes received, which `Plug.Parsers` consumes. Tell it to
read through this module:

    plug Plug.Parsers,
      parsers: [:urlencoded, :multipart, :json],
      pass: ["*/*"],
      json_decoder: Jason,
      body_reader: {Unicom360.Webhook.BodyReader, :read_body, []}

Then `conn.assigns.raw_body` holds the bytes for `Unicom360.Webhook.construct_event/4`, and
`Unicom360.Webhook.Plug` finds them there by itself.

This keeps a copy of every parsed body in memory for the length of its request. To limit
that to the webhook route, mount a separate `Plug.Parsers` (or `Unicom360.Webhook.Plug`
alone) ahead of the general one.

# `read_body`

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

Reads like `Plug.Conn.read_body/2`, appending what it read to `conn.assigns.raw_body`.

---

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