Slide 1

Slide 1 text

Phoenix @sasajuric

Slide 2

Slide 2 text

Erlang high availability Elixir dev productivity Phoenix batteries included

Slide 3

Slide 3 text

Phoenix/Elixir Nginx Redis Sidekick/Resque Cron theerlangelist.com

Slide 4

Slide 4 text

OTP Erlang VM (BEAM) Cowboy Elixir Plug Phoenix Ecto

Slide 5

Slide 5 text

defmodule Math do def sum(x, y) do x + y end end Math.sum(2, 3)

Slide 6

Slide 6 text

m1 = Map.new m2 = Map.put(m1, :x, 1) m3 = Map.put(m2, :y, 2)

Slide 7

Slide 7 text

bar(foo(x), y, z) foo(x) |> bar(y, z)

Slide 8

Slide 8 text

fun1(arg1) |> fun2(arg2) |> fun3(arg3) fun3(fun2(fun1(arg1), arg2), arg3)

Slide 9

Slide 9 text

fun1(arg1) |> fun2(arg2) |> fun3(arg3)

Slide 10

Slide 10 text

Map.new |> Map.put(:x, 1) |> Map.put(:y, 2) m1 = Map.new m2 = Map.put(m1, :x, 1) m3 = Map.put(m2, :y, 2)

Slide 11

Slide 11 text

defmodule MyRouter do get "/some_path", MyModule, :some_fun end defmodule MyRouter do def route(conn, "GET", "/some_path") do MyModule.some_fun(conn) end end

Slide 12

Slide 12 text

defmodule MyRouter do use Phoenix.Router get "/some_path", MyModule, :some_fun end

Slide 13

Slide 13 text

scheduler scheduler scheduler scheduler CPU CPU CPU CPU Erlang VM (BEAM)

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Plug.Adapters.Cowboy.http( MyServer, [], port: 5454 )

Slide 16

Slide 16 text

%Plug.Conn{ remote_ip: {151, 236, 219, 228}, host: "www.example.com", request_path: "/bar/baz", method: "GET", # ... }

Slide 17

Slide 17 text

defmodule MyServer do def init(opts), do: opts def call(conn, _opts) do conn |> Plug.Conn.put_resp_header("foo", "bar") |> Plug.Conn.put_resp_cookie("baz", "42") |> Plug.Conn.resp(200, "Hi!") end end

Slide 18

Slide 18 text

listener request 1 request 2 request 3 conn |>... conn |>... conn |>...

Slide 19

Slide 19 text

defmodule MyServer do use Plug.Builder plug Plug.RequestId plug Plug.Logger plug Plug.Static, at: "/static", from: "/folder" plug MyAuth plug :my_handle def my_handle(conn, opts) do # ... end end

Slide 20

Slide 20 text

Endpoint Router Controller View conn Model Controller View Model

Slide 21

Slide 21 text

$ mix phoenix.new hello --no-ecto # ... Fetch and install dependencies? [Yn] * running npm install && node node_modules/brunch/bin/brunch build * running mix deps.get We are all set! Run your Phoenix application: $ cd hello $ mix phoenix.server You can also run your app inside IEx (Interactive Elixir) as: $ iex -S mix phoenix.server

Slide 22

Slide 22 text

client server socket

Slide 23

Slide 23 text

socket

Slide 24

Slide 24 text

client server join "lobby" send "room:42", "{message: 'Hello'}" send "room:42", "{message: 'Hello'}" socket send "lobby", "{rooms: […]}" join "room:42"

Slide 25

Slide 25 text

socket channel client channel

Slide 26

Slide 26 text

channel channel PubSub subscribe("some_topic") broadcast("some_topic", some_data)

Slide 27

Slide 27 text

PubSub server 1 server 2 server 3

Slide 28

Slide 28 text

elixir-lang.org Getting started
 Mix & OTP www.phoenixframework.org

Slide 29

Slide 29 text

No content