Summary
In this chapter, we learned what controllers are both within and outside the context of a simple application. We then learned how Phoenix implements its controllers by utilizing Plug and how the entire request-response cycle, right from the router to the controllers, is powered by Plug. Taking that philosophy, we built our own controller interface and tested an example controller with both goldcrest_http_server
and cowboy
. To make our controller functionality more complete, we added the ability to redirect a request to another route by learning how redirects actually work in the context of a web browser. We finally wrapped up by using the Plug.Test
module to test our controller without having to start our HTTP server.
Similar to previous chapters, we didn’t cover all the functions that should be added to the Goldcrest.Controller
module to save time. We also didn’t write the render/3
implementation for HTML pages because we will cover that in a future chapter...