View Source Oasis.Controller (oasis v0.5.1)

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.

Returns the router module as an atom, raises if unavailable.

Sends text response.

Link to this section Functions

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

Sends html response.

examples

Examples

iex> html(conn, "<html>...</html>")
@spec json(Plug.Conn.t(), term()) :: Plug.Conn.t()

Sends JSON response.

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

examples

Examples

iex> json(conn, %{id: 1})
@spec router_module(Plug.Conn.t()) :: atom()

Returns the router module as an atom, raises if unavailable.

@spec text(Plug.Conn.t(), String.Chars.t()) :: Plug.Conn.t()

Sends text response.

examples

Examples

iex> text(conn, "hello")

iex> text(conn, :implements_to_string)