# `Oasis.Controller`
[🔗](https://github.com/xinz/oasis/blob/main/lib/oasis/controller.ex#L1)

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](https://hexdocs.pm/phoenix/Phoenix.Controller.html).

# `html`

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

Sends html response.

## Examples

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

# `json`

```elixir
@spec 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})

# `router_module`

```elixir
@spec router_module(Plug.Conn.t()) :: atom()
```

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

# `text`

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

Sends text response.

## Examples

    iex> text(conn, "hello")

    iex> text(conn, :implements_to_string)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
