Examples:
Successful Path Recognition
require "hanami/router"
router = Hanami::Router.new do
get "/books/:id", to: ->(*) { ... }, as: :book
end
route = router.recognize("/books/23")
route.verb
route.routable?
route.params
Successful Rack Env Recognition
require "hanami/router"
router = Hanami::Router.new do
get "/books/:id", to: ->(*) { ... }, as: :book
end
route = router.recognize(Rack::MockRequest.env_for("/books/23"))
route.verb
route.routable?
route.params
Successful Named Route Recognition
require "hanami/router"
router = Hanami::Router.new do
get "/books/:id", to: ->(*) { ... }, as: :book
end
route = router.recognize(:book, id: 23)
route.verb
route.routable?
route.params
Failing Recognition For Unknown Path
require "hanami/router"
router = Hanami::Router.new do
get "/books/:id", to: ->(*) { ... }, as: :book
end
route = router.recognize("/books")
route.verb
route.routable?
Failing Recognition For Path With Wrong HTTP Verb
require "hanami/router"
router = Hanami::Router.new do
get "/books/:id", to: ->(*) { ... }, as: :book
end
route = router.recognize("/books/23", method: :post)
route.verb
route.routable?
Failing Recognition For Rack Env With Wrong HTTP Verb
require "hanami/router"
router = Hanami::Router.new do
get "/books/:id", to: ->(*) { ... }, as: :book
end
route = router.recognize(Rack::MockRequest.env_for("/books/23", method: :post))
route.verb
route.routable?
Failing Recognition Named Route With Wrong Params
require "hanami/router"
router = Hanami::Router.new do
get "/books/:id", to: ->(*) { ... }, as: :book
end
route = router.recognize(:book)
route.verb
route.routable?
Failing Recognition Named Route With Wrong HTTP Verb
require "hanami/router"
router = Hanami::Router.new do
get "/books/:id", to: ->(*) { ... }, as: :book
end
route = router.recognize(:book, {method: :post}, {id: 1})
route.verb
route.routable?
route.params