Serving JSON with Plug and Bandit
HTTP/1.1 is readable and not that complicated, but writing a serialization layer for it is a pretty crazy idea. The protocol’s simplicity means that there are many corner cases—think of escaping characters when encoding headers, or encoding binary data. Plus, you want encoding requests and decoding responses to be fast. Using a battle-tested, optimized HTTP/1.1 serialization library is almost always the best choice.
We’ll look at Plug,[134] Elixir’s abstraction for HTTP server applications. Plug is an interface for implementing web servers, but it doesn’t implement connection pooling or transport-layer concerns. Instead, it needs a compatible HTTP server under the hood, so we’ll briefly touch on Bandit,[135] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access