crystal-routing
crystal-routing
Extensible library to deal with http request and string based routing in Crystal.
Features:
- Building blocks to define others routing/delegation mechanisms
- Compiled time check method invocation
Installation
Add this to your application's shard.yml
:
dependencies:
routing:
github: bcardiff/crystal-routing
Usage
# file: app.cr
require "http/server"
require "routing"
class FooController
include Routing::Routable
def method1
HTTP::Response.ok "text/plain", "method1"
end
def method2
HTTP::Response.ok "text/plain", routing_context.params["id"]
end
end
module App
class Routes
include Routing::HttpRequestRouter
get "m1", "foo#method1"
get "foo/:id", "foo#method2"
root "foo#method1"
end
end
routes = App::Routes.new
server = HTTP::Server.new(8080) do |request|
routes.route(request)
end
puts "Listening on http://0.0.0.0:8080"
server.listen
Run the server
$ crystal app.cr
Use the server
$ curl http://localhost:8080
method1
$ curl http://localhost:8080/m1
method1
$ curl http://localhost:8080/foo/42
42
More in samples and specs
Development
TODO: Write instructions for development
Contributing
- Fork it ( https://github.com/bcardiff/crystal-routing/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
- bcardiff Brian J. Cardiff - creator, maintainer
Repository
crystal-routing
Owner
Statistic
- 31
- 2
- 0
- 0
- 0
- almost 5 years ago
- July 8, 2015
License
MIT License
Links
Synced at
Thu, 21 Nov 2024 16:25:29 GMT
Languages