April 2016
Beginner to intermediate
300 pages
6h 58m
English
Before we build our plug, let’s take a deep dive into the Plug library and learn how plugs work from the inside. There are two kinds of plugs: module plugs and function plugs. A function plug is a single function. A module plug is a module that provides two functions with some configuration details. Either way, they work the same.
We have seen both kinds of plugs in use. From the endpoint module in lib/rumbl/endpoint.ex, you can see an example of a module plug:
| | plug Plug.Logger |
You specify a module plug by providing the module name. In the router, you can see an example of a function plug:
| | plug :protect_from_forgery |
You specify a function plug with the name of the function as an atom. Because a module is just a collection ...