Pharams v0.7.0 Pharams View Source

Functions and macros for validating requests to Phoenix Controllers.

Link to this section Summary

Functions

This macro provides the ability to define validation schemas for use in Phoenix controllers

Takes a nested struct data structure and turns it into a map with atoms as keys

Takes a nested struct data structure and turns it into a map with strings as keys

Link to this section Functions

Link to this macro pharams(controller_action, list) View Source (macro)

This macro provides the ability to define validation schemas for use in Phoenix controllers

Example

use Pharams, view_module: Pharams.ErrorView, view_template: "errors.json", error_status: :unprocessable_entity

pharams :index do
  required :terms_conditions, :boolean
  required :password, :string
  required :password_confirmation, :string
  optional :age, :integer
end

def index(conn, params) do
  # You will only get into this function if the request
  # parameters have passed the above validator. The params
  # variable is now just a map with atoms as keys.

  render(conn, "index.html")
end
Link to this function pharams_schema_to_atom_map(map) View Source

Takes a nested struct data structure and turns it into a map with atoms as keys.

Link to this function pharams_schema_to_string_map(map) View Source

Takes a nested struct data structure and turns it into a map with strings as keys