def resp(conn, _opts) do IO.inspect conn.method #=> GET conn |> put_resp_content_type("text/plain") |> send_resp(200, "") end end curl -XHEAD http://localhost:9001
def resp(conn, _opts) do conn |> put_resp_content_type("text/plain") |> send_resp(200, get_resp_header(conn, "x-request-id")) #=> "emv6tkni35sbvl38udbc4qvfhalgvfpj" end end
get "/hello" do send_resp(conn, 200, "world") end get "/hello/r*glob" do send_resp(conn, 200, "route after /hello: #{inspect glob}") end get "/hello/:name" do send_resp(conn, 200, "hello #{name}") end #(ଓ͘)
do send_resp(conn, 200, "hello world #{inspect(bar)}") end match "/foo/bar", via: :get do send_resp(conn, 200, "hello world") end #match ["foo", bar], via: :get do # send_resp(conn, 200, "hello world") #end match _ do send_resp(conn, 404, "oops") end end
alias ElixirPlugExamples.HttpPlug test "puts session cookie" do conn = conn(:get, "/") conn = ElixirPlugExamples.HttpPlug.call(conn, []) assert conn.resp_body == "xHello world" end end
:multipart] plug :resp def resp(conn, _opts) do case conn.params do %{"file" => file} -> IO.inspect file _ -> IO.puts "'file' key not found" end conn |> put_resp_content_type("text/plain") |> send_resp(200, "OK") end end Plug.Upload.start_link