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

Phoenix

 Phoenix

Ljubljana, 01.04.2016.

Saša Jurić

April 12, 2016
Tweet

More Decks by Saša Jurić

Other Decks in Programming

Transcript

  1. 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)
  2. 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
  3. 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
  4. 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
  5. $ 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
  6. client server join "lobby" send "room:42", "{message: 'Hello'}" send "room:42",

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