SuperPlug

Give your Plug superpowers!

Usage

defmodule FooPlug do
  use SuperPlug

  def init(opts) do
    ...
  end

  def call(conn, opts) do
    ...
  end
end

Primary Superpower

call/1 initializes default options.

FooPlug.call(conn)
# FooPlug.call(conn, FooPlug.init([]))

Secondary Superpower

call/2 initializes keyword options.

FooPlug.call(conn, bar?: true)
# FooPlug.call(conn, FooPlug.init(bar?: true))

Tertiary Superpower

call/2 short circuits if an error is assigned.

conn = %{assigns: %{error: :not_found}}
^conn = FooPlug.call(conn)

Installation

def deps do
  [
    {:super_plug, "~> 1.0"}
  ]
end