Oasis.Controller (oasis v0.2.1) View Source

Base on Plug.Builder, this module can be use-d into a module in order to build a plug pipeline:

defmodule MyApp.HelloController do
  use Oasis.Controller

  plug(Plug.Parsers,
    parsers: [:urlencoded],
    pass: ["*/*"]
  )

  def call(conn, opts) do
    conn = super(conn, opts)
    json(conn, %{"body_params" => conn.body_params})
  end
end

And provide some common functionality for easily use, this realization comes from Phoenix.Controller

Link to this section Summary

Functions

Sends html response.

Sends JSON response.

Sends text response.

Link to this section Functions

Specs

html(Plug.Conn.t(), iodata()) :: Plug.Conn.t()

Sends html response.

Examples

iex> html(conn, "<html>...</html>")

Specs

json(Plug.Conn.t(), term()) :: Plug.Conn.t()

Sends JSON response.

It uses Jason to encode the input as an iodata data.

Examples

iex> json(conn, %{id: 1})

Specs

Sends text response.

Examples

iex> text(conn, "hello")

iex> text(conn, :implements_to_string)