router
Version, currently 0.1.124 versions
- 0.2.9latestMay 16, 2022
- 0.2.8not indexedMay 16, 2022
- 0.2.7not indexedMay 16, 2022
- 0.2.6not indexedMay 16, 2022
- 0.2.5not indexedMay 16, 2022
- 0.2.4not indexedMay 16, 2022
- 0.2.3not indexedMay 16, 2022
- 0.2.2not indexedMay 16, 2022
- 0.2.1not indexedMay 16, 2022
- 0.2.0not indexedMay 16, 2022
- 0.1.13not indexedMay 16, 2022
- 0.1.12not indexedMay 16, 2022
- 0.1.11not indexedMay 16, 2022
- 0.1.10not indexedMay 16, 2022
- 0.1.9not indexedMay 16, 2022
- 0.1.8not indexedMay 16, 2022
- 0.1.7not indexedMay 16, 2022
- 0.1.6not indexedMay 16, 2022
- 0.1.5not indexedMay 16, 2022
- 0.1.4not indexedMay 16, 2022
- 0.1.3not indexedMay 16, 2022
- 0.1.2not indexedMay 16, 2022
- 0.1.1not indexedMay 16, 2022
- 0.1.0not indexedMay 16, 2022
github.com/jhelbig/router.cr
Minimum High Performance Middleware for Crystal Web Server.
Nothing has been indexed for 0.1.1 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
router:
github: jhelbig/router.cr
version: ~> 0.1.1Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.1. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
The default web server of the Crystal is quite good :smile: but it weak at routing :cry:.
Kemal or other web frameworks written in Crystal are awesome :smile:, but it's too fat for some purpose :cry:.
router.cr is a minimum but High Performance middleware for Crystal web server.
See the amazing performance of router.cr here.:rocket:
Installation
Add this to your application's shard.yml:
dependencies:
router:
github: tbrand/router.cr
Usage
Basic usage
require "router"
Include Router to utilize router.cr.
class WebServer
include Router
end
Define a method to draw all routes for your web server.
class WebServer
include Router
def draw_routes
# Drawing routes HERE!
end
end
In that method, call HTTP method name (downcase) like get or post with PATH and BLOCK where
- PATH : String
- BLOCK : block of HTTP::Server::Context, Hash(String, String) -> HTTP::Server::Context
class WebServer
include Router
def draw_routes
get "/" do |context, params|
context.response.print "Hello router.cr!"
context
end
end
end
Here we've defined a GET route at root path (/) that just print out "Hello router.cr" when we get access. To activate (run) the route, just define run methods for your server with route_handler
class WebServer
include Router
def draw_routes
get "/" do |context, params|
context.response.print "Hello router.cr!"
context
end
end
def run
server = HTTP::Server.new(route_handler)
server.bind_tcp 8080
server.listen
end
end
Here route_handler is getter defined in Router. So you can call route_handler at anywhere in WebServer instance.
Finally, run your server.
web_server = WebServer.new
web_server.draw_routes
web_server.run
See sample and tips for details.
Path parameters
params is a Hash(String, String) that is used when you define a path parameters such as /user/:id (:id is a parameters). Here is an example.
class WebServer
include Router
def draw_routes
get "/user/:id" do |context, params|
context.response.print params["id"] # get :id in url from params
context
end
end
end
See sample and tips for details.
Contributing
- Fork it ( https://github.com/tbrand/router.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
Contributors
- tbrand Taichiro Suzuki - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.1- Tagged
- May 16, 2022
- Commit
15943318740d- Indexed
- not yet
Dependents
Repository
github.com/jhelbig/router.cr
Metadata
- Created
- Aug 18, 2026
- Updated
- Sep 17, 2026
- Synced
- Sep 17, 2026
- Versions
- 24