onyxframework / onyx

Powerful framework for modern applications 💪
https://api.onyxframework.com/onyx
MIT License
78 stars 5 forks source link

with self yield in router #25

Open watzon opened 5 years ago

watzon commented 5 years ago

If the #on method were to yield as with self yield self rather than simply yield self it would switch the entire context to self rather than just yielding self to the block. This would allow for slightly more idomatic routing as you could then do

Onyx::HTTP.on "/api" do
  get "/ping", Endpoints::API::Ping
end

Instead of

Onyx::HTTP.on "/api" do |router|
  router.get "/ping", Endpoints::API::Ping
end
vladfaust commented 5 years ago

May be. Try to play with https://github.com/onyxframework/onyx/blob/8af5c07efe7e423d0c8a991d086f946260c10f6a/src/onyx/http.cr#L35

To see how it would work.