Skip to content

Instantly share code, notes, and snippets.

@erez-rabih
Last active March 1, 2018 12:59
Show Gist options
  • Save erez-rabih/6b3709d977202d0f44e71232f633d5c9 to your computer and use it in GitHub Desktop.
Save erez-rabih/6b3709d977202d0f44e71232f633d5c9 to your computer and use it in GitHub Desktop.
defmodule Plug.Support.Router do
import Plug.Conn
use Plug.Router
import Plug.Support.Validators,
only: [validate_integer: 1, validate_boolean: 1, on_error_fn: 2, json_resp: 3]
plug :match
plug Plug.Validator, on_error: &on_error_fn/2
plug :dispatch
get "/users/:id",
private: %{validate: %{id: &validate_integer/1, active: &validate_boolean/1}} do
json_resp(conn, 200, %{id: 1, name: "user1"})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment