Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bcardiff/crystal-routing
Extensible library to deal with http request and string based routing in Crystal
https://github.com/bcardiff/crystal-routing
Last synced: 2 months ago
JSON representation
Extensible library to deal with http request and string based routing in Crystal
- Host: GitHub
- URL: https://github.com/bcardiff/crystal-routing
- Owner: bcardiff
- License: mit
- Created: 2015-07-08T04:04:07.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-01-17T21:34:15.000Z (over 4 years ago)
- Last Synced: 2024-01-31T09:58:42.967Z (5 months ago)
- Language: Crystal
- Size: 14.6 KB
- Stars: 31
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-crystal - crystal-routing - Extensible library to deal with http request and string based routing (HTTP)
README
# crystal-routing
[![Build Status](https://travis-ci.org/bcardiff/crystal-routing.svg)](https://travis-ci.org/bcardiff/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`:
```crystal
dependencies:
routing:
github: bcardiff/crystal-routing
```## Usage
```crystal
# file: app.cr
require "http/server"
require "routing"class FooController
include Routing::Routabledef method1
HTTP::Response.ok "text/plain", "method1"
enddef method2
HTTP::Response.ok "text/plain", routing_context.params["id"]
end
endmodule App
class Routes
include Routing::HttpRequestRouterget "m1", "foo#method1"
get "foo/:id", "foo#method2"
root "foo#method1"
end
endroutes = App::Routes.new
server = HTTP::Server.new(8080) do |request|
routes.route(request)
endputs "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
1. Fork it ( https://github.com/bcardiff/crystal-routing/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request## Contributors
- [bcardiff](https://github.com/bcardiff) Brian J. Cardiff - creator, maintainer