exvalidate v0.0.1 Exvalidate.Plug View Source

Plug for validate request into the router file. For validate the request we need create a schema keywordlist with the rules assigned to params.

Uses

1- To add the exvalidate middleware in your plug file:

plug(:match)
plug(PlugValidate, on_error: &PlugError.json_error/2)
plug(:dispatch)

2- Schema example:

@schema = [
  name: [between: {2, 16}]
]

3a- if the request contains query string (for GET request) the validation will be: "private: %{validate_query: @schema}"

get "/test", private: %{validate_query: @schema} do

3b- if the request container body params (for POST request) the validation will be: "private: %{validate_body: @schema}"

post "/test", private: %{validate_body: @schema} do