Phoenix for Rubyists

Phoenix Framework draws heavily upon important foundations in the opinionated web frameworks that came before it, like Ruby on Rails.

Phoenix for Rubyists

Request, Response

A Phoenix app can basically be boiled down to a function that receives a HTTP request, and returns a response. We'll begin with this premise, and start to understand the important parts involved in this process.

  • Request, ResponseEndpoint & Routing

    Requests enter your app through an Endpoint, and your app usually will have only one. We'll look at this chain of Elixir Plugs, which ends at the Router, the module ultimately responsible for delegating request-handling to an appropriate Controller.

  • Request, ResponsePlugs & Pipelines

    Plugs are at the core of Phoenix, and they're a relatively simple and approachable concept: things that accept a connection as an argument, and return a slightly-modified connection.

    Chain a few plugs together, and it's easy to see how basic building blocks start to assemble into a complete application.

  • Request, ResponseEXERCISE: Routing to the Pages controller

    Add a new page to your app, following the existing example set up in your PageController

  • Request, ResponseEXERCISE: Hating on a Content-Type

    Build a Plug that interrupts the pipeline (returning a HTTP error for an incoming request) if we ever request a SOAP XML document (Content-Type: application/soap+xml)

  • Request, ResponseThe Controller Responds

    Now that we understand how to leverage Phoenix's routing layer, let's take a closer look at Controllers: the modules ultimately responsible for responding to a request.

  • Request, ResponseViews & Templates

    In a welcome contrast to other web frameworks, Phoenix's view layer is exceedingly easy to understand and use.

    Judging by how easy it is to keep views simple, performant, and easy to manage, It's clear that the hard-learned lessons from older frameworks have paid off.

  • Request, ResponseEXERCISE: Assigns & Functional Views

    We'll pass some data from the Phoenix controller layer to the view layer, and leverage view functions to do some light formatting & massaging.