onyx icon indicating copy to clipboard operation
onyx copied to clipboard

with self yield in router

Open watzon opened this issue 6 years ago • 1 comments

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

watzon avatar Sep 19 '19 23:09 watzon

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

To see how it would work.

vladfaust avatar Sep 20 '19 08:09 vladfaust