The Plug specification
Plug is a very central component of Phoenix, and as is stated in the documentation, lives at the heart of Phoenix's HTTP layer. The plug specification allows us to compose modules in web applications, abstracting the concept of a connection. Plug embraces the functional nature of Elixir and handles web requests by making a series of transformations on the connection, which eventually will be used to render the response.
There are two types of plugs: function plugs and module plugs. Regardless of the type, Plug's specification is very simple: a Plug must accept a connection and return a (possibly) modified connection. Later in this section, we'll explore what a connection is. Reading this elementary description, it's hard to imagine that Plug is at the heart of Phoenix. However, this simple concept is incredibly powerful, which becomes evident when you start to chain plugs together to achieve sophisticated functionality. Many of Phoenix's powerful constructs, such as...