simple path router inspired by Router::Simple.
Add it to Projectfile
deps do
github "karupanerura/router-simple.cr"
end
require "router-simple"
dispatcher = Router::Simple::Dispatcher(Hash(Symbol, String)).new()
dispatcher.add("/", {
:controller => "Root",
:action => "index",
})
dispatcher.add("/users/:user_id", {
:controller => "Users",
:action => "fetch_by_id",
})
dispatcher.match("/") {|result|
p result.route.meta[:controller] # => "Root"
}
dispatcher.match("/users/1") {|result|
p result.route.meta[:controller] # => "Users"
p result.match["user_id"] # => "1"
}
TODO: Write instructions for development
- Fork it ( https://github.com/karupanerura/router-simple.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- karupanerura(https://github.com/karupanerura) karupanerura - creator, maintainer