router.cr icon indicating copy to clipboard operation
router.cr copied to clipboard

Feature Request: Add method or class handler

Open iambudi opened this issue 5 years ago • 1 comments

As addition to use block handler, it would be nice to add method handler or class handler to make the router code cleaner and follow separation of concern.

# block handler
get "/" do |context, params|
 context.response.print "Hello router.cr!"
 context
end

# method handler
get "/" home
post "/user" add_user

def home(context, params) : HTTP::Server::Context
  context.response.print "Hello router.cr!"
  context
end

# class handler
article = Article.new
get "/article/:id" article.get 
put "/article/:id" article.update 

class Article
  def get(context, params)
    context.response.print "Hello router.cr!"
    context
  end
end

iambudi avatar Mar 09 '19 07:03 iambudi

Sounds good. :+1:

I don't have much time to work on it. Someone help us or you could send a pull request. 😍

tbrand avatar Mar 12 '19 06:03 tbrand