CastParams


Build StatusHex pmCoverage Status

Casting params in Phoenix controllers.

defmodule AppWeb.ExampleController do
  use AppWeb, :controller
  use CastParams

  cast_params(category_id: :integer) when action == :index
  cast_params(name: :string!, terms: :boolean!) when action == :create

  def index(conn, %{"category_id" => category_id}) do
    # some code
  end

  def create(conn, %{"name" => name, "terms" => terms} = params) do
    # some code
  end
end

Documentation can be found at https://hexdocs.pm/cast_params.

Installation

If available in Hex, the package can be installed by adding cast_params to your list of dependencies in mix.exs:

def deps do
  [
    {:cast_params, ">= 0.0.1"}
  ]
end

License

This software is licensed under the MIT license.