Maxwell: One HTTP Client to Rule Them All

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

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

  • send_file with chunked or without chunked.
  • 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.