Placid.Response.Helpers
Placid bundles these response helpers with handlers to assist in sending a response.
Example
defmodule Hello do
use Placid.Handler
def index(conn, []) do
render conn, "showing index handler"
end
def show(conn, args) do
forward conn, OtherHandler, :show, args
end
def create(conn, []) do
render conn, "page created"
|> status(201)
|> send_resp
end
end
Summary
| forward(conn, handler, action, args \\ []) | Forwards the response to another handler action |
| halt!(conn, opts \\ []) | Ends the response |
| headers(conn, headers) | sets response headers |
| not_found(conn, message \\ "Not Found") | Sends a 404 (Not found) response |
| raw(conn) | Sends response as-is. It is expected that status codes, headers, body, etc have been set by the handler action |
| redirect(conn, location, opts \\ []) | Redirects the response |
| render(conn, data, opts \\ []) | Sends a normal response |
| status(conn, status_code) | sets connection status |
Functions
Specs:
- forward(Plug.Conn.t, atom, atom, Keyword.t) :: Plug.Conn.t
Forwards the response to another handler action.
Arguments
conn-Plug.Connhandler-Atomaction-Atomargs-Keyword
Returns
Plug.Conn
Specs:
- halt!(Plug.Conn.t, Keyword.t) :: Plug.Conn.t
Ends the response.
Arguments
conn-Plug.Connopts-Keyword
Returns
Plug.Conn
Specs:
- headers(Plug.Conn.t, Plug.Conn.headers) :: Plug.Conn.t
sets response headers
Arguments
conn-Plug.Connheaders-Map
Returns
Plug.Conn
Specs:
- not_found(Plug.Conn.t, binary) :: Plug.Conn.t
Sends a 404 (Not found) response.
Arguments
conn-Plug.Conn
Returns
Plug.Conn
Specs:
- raw(Plug.Conn.t) :: Plug.Conn.t
Sends response as-is. It is expected that status codes, headers, body, etc have been set by the handler action.
Arguments
conn-Plug.Conn
Returns
Plug.Conn
Specs:
- redirect(Plug.Conn.t, binary, Keyword.t) :: Plug.Conn.t
Redirects the response.
Arguments
conn-Plug.Connlocation-Stringopts-Keyword
Returns
Plug.Conn
Specs:
- render(Plug.Conn.t, enumerable, Keyword.t) :: Plug.Conn.t
Sends a normal response.
Arguments
conn-Plug.Conndata-Enumerableopts-Keyword
Returns
Plug.Conn
Specs:
- status(Plug.Conn.t, status_code) :: Plug.Conn.t
sets connection status
Arguments
conn-Plug.Connstatus_code-Integer
Returns
Plug.Conn