phoenixframework/phoenix — pull request #50 by mathieul (2014-02-23 16:39:47+00:00)
Title: Testing adding controller filters using plugs

Thank you for Phoenix, it looks like such a promising web framework, and the design and code are so clean and simple.

This pull request is more a question around controller filters. Do you intend to add a filter feature similar to Rails before/around/after filters? This pull request is a basic implementation using Plug. Implementing around and after filters would be more complex, but maybe not necessary.

With this implementation you can use `Plug.Builder` in the controllers to add plugs to be executed before the action:

```elixir
# Router
resources "accounts", Controllers.Accounts

# Account controller
use Phoenix.Controller
use Plug.Builder

plug :authenticate_token, except: [ :index, :show]

# actions
...

def authenticate_token(conn, options) do
...
conn
end
```

We can use regular plugs (function or module) for filters that don't need to break the stack chain, or plug wrappers if we need more flexibility or just stop the chain.

Do you already have different or similar plans? Is it worth spending some time to implement this with tests and maybe a couple macros for a more consistent DSL?