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

Phoenix

 Phoenix

LambdaZg Meetup

78d85ea26770975ea8c497d7bd722d55?s=128

Saša Jurić

November 25, 2015
Tweet

Transcript

  1. Phoenix @sasajuric

  2. concurrency scalability fault tolerance predictable latency distributed systems high availability

  3. “MVC” router sessions assets real-time communication dev productivity

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

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

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

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

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

  9. a |> b |> c c(b(a))

  10. a |> b |> c

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

  14. scheduler scheduler scheduler scheduler CPU CPU CPU CPU VM

  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

  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 join "room:23" send "room:23", "Hello" send "room:23", "Hi"

    Socket
  23. socket channel client channel PubSub

  24. PubSub server 1 server 2 server 3

  25. maturity CPU bound tasks learning curve

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

  27. None