Maxwell: One HTTP Client to Rule Them All

Jan 3, 2017 · 2 min read
Image for post
Image for post

Maxwell is a Elixir HTTP client which allow developers to customize its behavior with middleware. If you’re familiar with Faraday or Plug, then you’ll love Maxwell. Rather than re-implement yet another HTTP client, Maxwell has adapters for popular libraries like httpc, ibrowse, hackney. On top of having a consistent interface between different adapters. This tutorial gives an introduction of common use cases built into Maxwell, and also explains how to extend Maxwell with custom middleware

Basics Usage

Out of the box, Maxwell functions like Plug with a easy to use interface.

There are a number of Maxwell.Conn functions for manipulating connection details. Check out the Maxwell.Conn documentation for a full list.

Middleware Usage

The client will decode response body to json by Maxwell.Middleware.Json.

Adapter Advanced Usage

All adapters support send_file, send_multipart, send_stream.

Writing own Middleware

defmodule MyMiddleware do
import Maxwell.Conn

def init(options) do
# initialize options

def call(conn, next_fn, opts) do
|> deal_with_request
|> next_fn.()
|> deal_with_response

Find More detail example in Maxwell.Middleware.Logger.

Maxwell VS Tesla


Maxwell and Tesla all support middleware and multiple adapters.


Maxwell’s code is clean, well tested and easy to follow, so I recommend browsing the source code to find extra options and features not covered in this tutorial.
It’s a piece of cake to use Maxwell, if you already get used to Plug’s code.
Because they have a lot of similarities.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store