This module can be use-d into a module in order to build
a plug pipeline:

defmoduleMyAppdousePlug.BuilderplugPlug.Loggerplug:hello,upper:true# A function from another module can be plugged too, provided it's# imported into the current module first.importAnotherModule,only:[interesting_plug:2]plug:interesting_plugdefhello(conn,opts)dobody=ifopts[:upper],do:"WORLD",else:"world"send_resp(conn,200,body)endend

Multiple plugs can be defined with the plug/2 macro, forming a pipeline.
The plugs in the pipeline will be executed in the order they’ve been added
through the plug/2 macro. In the example above, Plug.Logger will be
called first and then the :hello function plug will be called on the
resulting connection.

Options

:log_on_halt - accepts the level to log whenever the request is halted

:init_mode - the environment to initialize the plug’s options, one of
:compile or :runtime. Defaults :compile.

Plug behaviour

Internally, Plug.Builder implements the Plug behaviour, which means both
the init/1 and call/2 functions are defined.

By implementing the Plug API, Plug.Builder guarantees this module is a plug
and can be handed to a web server or used as part of another pipeline.

Overriding the default Plug API functions

Both the init/1 and call/2 functions defined by Plug.Builder can be
manually overridden. For example, the init/1 function provided by
Plug.Builder returns the options that it receives as an argument, but its
behaviour can be customized:

The call/2 function that Plug.Builder provides is used internally to
execute all the plugs listed using the plug macro, so overriding the
call/2 function generally implies using super in order to still call the
plug chain:

Halting a plug pipeline

A plug pipeline can be halted with Plug.Conn.halt/1. The builder will
prevent further plugs downstream from being invoked and return the current
connection. In the following example, the Plug.Logger plug never gets
called:

It will print [custom: :options] as the builder options
were passed to the inner plug.

Note you only pass builder_opts() to function plugs.
You cannot use builder_opts() with module plugs because
their options are evaluated at compile time. If you need
to pass builder_opts() to a module plug, you can wrap
the module plug in function. To be precise, do not do this: