Download - Phoenix for Rubyists - Rubyconf Brazil 2016
@MichaelLNorth
Phoenix for Rubyists
Rubyconf Brazil 2016
Mike North CTO, Levanto Financial
image credit: http://phoenix-mask.deviantart.com/art/Ruby-Heart-s-Cutie-Mark-600784264
@MichaelLNorth
My Perspective
@MichaelLNorth
@MichaelLNorth
Origins
@MichaelLNorth
Concurrency +
Rails
@MichaelLNorth
@MichaelLNorth
@MichaelLNorth
š±š±
š±š±
š¼
@MichaelLNorth
Ericsson AXE Switch (1976 - Present)
@MichaelLNorth
š±š±
š±š±
š¼
@MichaelLNorth
š„š±
š»ā
ā
@MichaelLNorth
š„š±
š»ā ā
ā
@MichaelLNorth
Concurrencyš±š±
š±š±
š¼
@MichaelLNorth
Performance
RubyErlang
@MichaelLNorth
Fault Tolerance
@MichaelLNorth
Beautiful Syntax & Developer Ergonomics
@MichaelLNorth
Beautiful Syntax & Developer Ergonomics
@MichaelLNorth
@MichaelLNorth
@MichaelLNorth
TL;DR
@MichaelLNorth
TL;DR Functional
@MichaelLNorth
TL;DR Functional Immutable
@MichaelLNorth
TL;DR Functional Immutable
BEAM
@MichaelLNorth
TL;DR Functional Immutable
BEAM Extensible
@MichaelLNorth
Apps
@MichaelLNorth
S
S
W W W
Hierarchy of Apps
@MichaelLNorth
|>
Pipe Forward
@MichaelLNorth
|>
Pipe Forward
@MichaelLNorth
val |> func
Pipe Forward
func(val)
@MichaelLNorth
val |> func(b)
Pipe Forward
func(val, b)
@MichaelLNorth
val |> func(b) |> other(c) |> more(d)
Pipe Forward
more(other(func(val, b), c), d)
@MichaelLNorth
Connection
@MichaelLNorth
conn
Request Body Request Params Request Headers Request Origin
Response Body Response Status Code
Response Headers
new_conn
Request Body Request Params Request Headers Request Origin
Response Body Response Status Code
Response Headers
@MichaelLNorth
Phoenix, Abbreviated
new_conn = conn |> MyApp.handleRequest
@MichaelLNorth
@MichaelLNorth
Start your app
Start your app (w/ CLI)
Create your DB
@MichaelLNorth
RakeBundler MIX
An Elixir App (with Phoenix 1.2)
Beam files
An Elixir App (with Phoenix 1.2)
App configuration
An Elixir App (with Phoenix 1.2)
Dependency Source Code
An Elixir App (with Phoenix 1.2)
Application (non-web)
An Elixir App (with Phoenix 1.2)
Elixir Package Manifest++
An Elixir App (with Phoenix 1.2)
JS Dependency Source
An Elixir App (with Phoenix 1.2)
JS Package Manifest
An Elixir App (with Phoenix 1.2)
DB stuff, Static assets
An Elixir App (with Phoenix 1.2)
Guess what this is
An Elixir App (with Phoenix 1.2)
Application (web)
An Elixir App (with Phoenix 1.2)
98% of your time
An Elixir App (with Phoenix 1.2)
@MichaelLNorth
Start the server
HTTP://LOCALHOST:4000
@MichaelLNorth
Whatās going on?URL
Pipeline Parameters Controller Action
@MichaelLNorth
Endpoint
@MichaelLNorth
Multiplexing Socket
@MichaelLNorth
Serve static assets
@MichaelLNorth
Request ID
@MichaelLNorth
Request Logging
@MichaelLNorth
Request body normalization
into JSON
@MichaelLNorth
AJAX DELETE/PATCH/PUT
@MichaelLNorth
AJAX HEAD
@MichaelLNorth
Session
@MichaelLNorthYour appās router
@MichaelLNorth
Phoenix, Abbreviated
new_conn = conn |> Lots of plugs |> Router
@MichaelLNorth
Routing
@MichaelLNorth
pipeline(chain of plugs) Content-type
Use sessionNotificationsCSRFx-frame, etcā¦
@MichaelLNorth
Scope
@MichaelLNorth
ActionControllerPathVerb
@MichaelLNorth
Controllers
@MichaelLNorth
RENDER
ā¢Can specify a view, but we didnāt
ā¢Default behavior: name-matching
render(conn, view, template, assigns)
RENDER
ā¢Can specify a view, but we didnāt
ā¢Default behavior: name-matching
render(conn, template, assigns)
Implied: use view with the same name
RENDER
ā¢Can specify a view, but we didnāt
ā¢Default behavior: name-matching
render(conn, template_or_assigns)
Implied: use view with the same name
@MichaelLNorth
Base Controller
@MichaelLNorth
Filters
@MichaelLNorth
View Layer
@MichaelLNorth
web/controllers/page_controller.ex web/templates/page/index.html.eex
web/views/page_view.ex
@MichaelLNorth
@MichaelLNorth
Model Layer
mix phoenix.gen.model User \ users \ name:string \ username:string \ password_hash:string
Model Name
mix phoenix.gen.model User \ users \ name:string \ username:string \ password_hash:string
Table Name
mix phoenix.gen.model User \ users \ name:string \ username:string \ password_hash:string
Schema
model test
model
db migration
SCHEMA
CHANGESET STUFF
WEB/MODELS/USER.EX
@MichaelLNorth
Migrating
@MichaelLNorth
Migrating
ā¢ One-shot rewrites are expensive and dangerous
ā¢ You suffer, your company suffers, your users suffer
ā¢ Incremental change makes everyone happier
@MichaelLNorth
Reverse Proxy
Rails Phoenix
@MichaelLNorth
Reverse Proxy
Phoenix Rails
@MichaelLNorth
Terraformpoteto/terraform
@MichaelLNorth
Phoenix is the future
@MichaelLNorth
You have an advantage
Phoenix is the future
@MichaelLNorth
You have an advantage
Phoenix is the future
Learn it, try it, use it!
@MichaelLNorth
ā¢https://www.toptal.com/erlang/a-cloud-at-the-lowest-level-built-in-erlang ā¢https://en.wikipedia.org/wiki/Moore%27s_law ā¢https://theerlangelist.blogspot.in/2013/05/working-with-immutable-data.html ā¢https://www.amberbit.com/blog/2014/2/14/putting-ruby-on-rails-on-a-diet/ ā¢https://www.technologyreview.com/s/601441/moores-law-is-dead-now-what/
IMAGE & DIAGRAM CREDITS
Thanks!
Iām available for elixir training & consulting!