Req.NDJSON (req v0.8.0-rc.0)

Copy Markdown View Source

NDJSON decoding.

Each line is decoded as a separate JSON document. This module is used by Req.Decode on application/x-ndjson and application/ndjson.

Examples

iex> {:ok, resp, acc} =
...>   Req.stream(
...>     "http://httpbingo.org/stream/2",
...>     [],
...>     fn data, _resp, acc ->
...>       IO.inspect(data)
...>       {:cont, acc}
...>     end,
...>     decoders: [text: :ndjson] # endpoint sends content-type: text/plain
...>                               # so let's force ndjson.
...>   )
# Output: %{"id" => 0, ...}
# Output: %{"id" => 1, ...}
iex> resp.status
200
iex> resp.body
nil