Adding Controller Plugs and Action Fallback
In the last chapter, we built a framework to write a controller and wrapped it inside the Goldcrest.Controller
module. In this chapter, we will learn about extending the functionality of our controllers by intercepting an incoming request and calling specific plugs on it based on the controller’s definition before letting the controller’s actions handle that request. This will give developers the means to add better control of the request flow while keeping their controller code simple and digestible. We will learn how to use the Plug.Builder
module to build a pipeline of plugs in a controller. We will then learn how to apply a pipeline of plugs to an action and how to define a fallback controller to capture any errors.
By the end of the chapter, you will understand Plug.Builder
enough to build complex plug pipelines without needing Phoenix or any other libraries other than Plug itself. You will also learn how Phoenix implements...