Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Phoenix

 Phoenix

Ljubljana, 01.04.2016.

78d85ea26770975ea8c497d7bd722d55?s=128

Saša Jurić

April 12, 2016
Tweet

Transcript

  1. Phoenix @sasajuric

  2. Erlang high availability Elixir dev productivity Phoenix batteries included

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

  4. OTP Erlang VM (BEAM) Cowboy Elixir Plug Phoenix Ecto

  5. defmodule Math do def sum(x, y) do x + y

    end end Math.sum(2, 3)
  6. m1 = Map.new m2 = Map.put(m1, :x, 1) m3 =

    Map.put(m2, :y, 2)
  7. bar(foo(x), y, z) foo(x) |> bar(y, z)

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

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

  10. 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)
  11. 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
  12. defmodule MyRouter do use Phoenix.Router get "/some_path", MyModule, :some_fun end

  13. scheduler scheduler scheduler scheduler CPU CPU CPU CPU Erlang VM

    (BEAM)
  14. None
  15. Plug.Adapters.Cowboy.http( MyServer, [], port: 5454 )

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

    method: "GET", # ... }
  17. 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
  18. listener request 1 request 2 request 3 conn |>... conn

    |>... conn |>...
  19. 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
  20. Endpoint Router Controller View conn Model Controller View Model

  21. $ 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
  22. client server socket

  23. socket

  24. client server join "lobby" send "room:42", "{message: 'Hello'}" send "room:42",

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

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

  27. PubSub server 1 server 2 server 3

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

  29. None