# `KapsoEx.Webhook.CacheBodyReader`
[🔗](https://github.com/rocket4ce/kapso_ex/blob/v0.1.0/lib/kapso_ex/webhook/cache_body_reader.ex#L2)

A `Plug.Parsers` body reader that keeps the raw request body, which is
needed to verify webhook signatures after the JSON has been parsed.

    plug Plug.Parsers,
      parsers: [:json],
      pass: ["*/*"],
      body_reader: {KapsoEx.Webhook.CacheBodyReader, :read_body, []},
      json_decoder: Jason

Then read it back with `raw_body/1`. Only available when `:plug` is a
dependency of your application.

# `raw_body`

```elixir
@spec raw_body(Plug.Conn.t()) :: binary() | nil
```

Returns the raw body cached by `read_body/2`, or `nil` when it was not read.

# `read_body`

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

Reads the body like `Plug.Conn.read_body/2` and stores a copy in `conn.private`.

---

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