christopheradams
New Router features in Plug 1.3
I blogged about a new feature that I developed for Plug that was merged in and released in the brand-new version 1.3.0.
https://christopheradams.io/articles/2016/11/new-router-features-in-plug-1-3/
If you’re familiar with Phoenix, you might know that its Router macros all take a plug module as an argument (a Controller is just a Plug). In Phoenix that looks like:
get "/hello", HelloPlug, options
Now you can do a similar thing in Plug Router:
get "/hello", to: HelloPlug, init_opts: options
In previous versions, if you wanted to route (not forward) to another plug, you’d have to do it manually:
get "/hello" do
HelloPlug.call(conn, HelloPlug.init(options))
end
This new feature opens up possibilities for dispatching requests to Controller-like resource modules, rather than filling up the router with function bodies.
In addition, any values for dynamic routes like get "/hello/:name" will be saved in conn.params and conn.path_params.
Looking forward to you using this!
Most Liked
svarlet
Nice, thanks, good job!
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









