Slide 7
Slide 7 text
P H O E N I X F R A M E W O R K
Plugs
Just like stars and the whole
universe, when we develop a
Phoenix application we are
leveraging the power of the Elixir
ecosystem, and Plugs are all around
us. Phoenix is entirely based upon
Plugs, and we can plug additional
functions basically inside every
layer.
Inside every step of our connection
lifecycle we can write plugs to
manipulate what travels from the
endpoint to the very Phoenix’ core.
def put_headers(conn, key_values) do
Enum.reduce key_values, conn, fn {k, v}, conn !->
Plug.Conn.put_resp_header(conn, to_string(k), v)
end
end
…
defmodule HelloWeb.MessageController do
use HelloWeb, :controller
plug :put_headers, %{content_encoding: "gzip",
cache_control: "max-age=3600"}
plug :put_layout, "bare.html"
!!...
end