Summary
In this chapter, we learned how modern web frameworks such as Rails and Phoenix define a way to hook into a request from a controller, check for certain conditions, and in some cases, halt the request pipeline. We then learned about the details of the Plug.Builder
module, how to implement it, and how we can use it to add that feature into our controller.
After learning how to test our Plug.Builder
module, we learned how to use the overridable call/2
function to define a fallback plug for a controller action. In this way, we can standardize the error handling across many controllers, allowing developers to focus on the happy path while writing the controllers.
Now that we have a working set of controllers and routers for our web framework, we will focus on adding views and HTML templates in a dynamic, server-rendered manner in the next chapter.