Route Requests Through Phoenix
As requests come into an application, it’s important that they get sent to the right function in your application. Along the way, they’ll get transformed and interacted with by middleware functions. Middleware can serve any purpose, but you’ll often write middleware to set common data and validate that the request can be served.
Phoenix uses the Plug[70] library, which refers to middleware as “plugs.” Plugs can be either functions or modules.
Let’s look at how Phoenix encapsulates plugs inside of the Phoenix.Endpoint module. Once we get these basics down, we’ll move on to our controller.
How Requests Flow
The Phoenix generator creates several files as part of its generation process. These files relate to one ...
Get From Ruby to Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.