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

Types

status_code :: atom | 100 .. 999

enumerable :: Map | List

Functions

forward(conn, handler, action, args \\ [])

Specs:

  • forward(Plug.Conn.t, atom, atom, Keyword.t) :: Plug.Conn.t

Forwards the response to another handler action.

Arguments

  • conn - Plug.Conn
  • handler - Atom
  • action - Atom
  • args - Keyword

Returns

Plug.Conn

halt!(conn, opts \\ [])

Specs:

  • halt!(Plug.Conn.t, Keyword.t) :: Plug.Conn.t

Ends the response.

Arguments

  • conn - Plug.Conn
  • opts - Keyword

Returns

Plug.Conn

headers(conn, headers)

Specs:

  • headers(Plug.Conn.t, Plug.Conn.headers) :: Plug.Conn.t

sets response headers

Arguments

  • conn - Plug.Conn
  • headers - Map

Returns

Plug.Conn

not_found(conn, message \\ "Not Found")

Specs:

  • not_found(Plug.Conn.t, binary) :: Plug.Conn.t

Sends a 404 (Not found) response.

Arguments

  • conn - Plug.Conn

Returns

Plug.Conn

raw(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

redirect(conn, location, opts \\ [])

Specs:

  • redirect(Plug.Conn.t, binary, Keyword.t) :: Plug.Conn.t

Redirects the response.

Arguments

  • conn - Plug.Conn
  • location - String
  • opts - Keyword

Returns

Plug.Conn

render(conn, data, opts \\ [])

Specs:

Sends a normal response.

Arguments

  • conn - Plug.Conn
  • data - Enumerable
  • opts - Keyword

Returns

Plug.Conn

status(conn, status_code)

Specs:

sets connection status

Arguments

  • conn - Plug.Conn
  • status_code - Integer

Returns

Plug.Conn