Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allevo/bravery_router
Router for bravery http framework
https://github.com/allevo/bravery_router
Last synced: 14 days ago
JSON representation
Router for bravery http framework
- Host: GitHub
- URL: https://github.com/allevo/bravery_router
- Owner: allevo
- License: mit
- Created: 2019-04-24T22:41:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-29T14:25:06.000Z (about 5 years ago)
- Last Synced: 2024-08-09T02:25:41.414Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bravery_router
[![Build Status](https://travis-ci.org/allevo/bravery_router.svg?branch=master)](https://travis-ci.org/allevo/bravery_router)Fast HTTP router
## Install
Add the following line into your `Cargo.toml`
```
bravery_router = "*"
```## Usage
```rust
use bravery_router::{add, optimize, find, create_root_node};fn main() {
let mut root = create_root_node();add(&mut root, "/foo", 1);
add(&mut root, "/foobar", 2);
add(&mut root, "/users/:id", 3);
add(&mut root, "/all/*", 4);let root = optimize(root);
let empty_vec: Vec<&str> = vec![];
let ret = find(&root, "/foo");
assert_eq!(ret.value, Some(&1));
assert_eq!(ret.params, empty_vec);
println!("/foo, {:?}, {:?}", ret.value, ret.params);let ret = find(&root, "/foobar");
assert_eq!(ret.value, Some(&2));
assert_eq!(ret.params, empty_vec);
println!("/foobar, {:?}, {:?}", ret.value, ret.params);let ret = find(&root, "/users/42");
assert_eq!(ret.value, Some(&3));
assert_eq!(ret.params, vec!["42"]);
println!("/users/42, {:?}, {:?}", ret.value, ret.params);let ret = find(&root, "/all/foo/bar");
assert_eq!(ret.value, Some(&4));
assert_eq!(ret.params, vec!["foo/bar"]);
println!("/all/foo/bar, {:?}, {:?}", ret.value, ret.params);let ret = find(&root, "/unknwon");
assert_eq!(ret.value, None);
assert_eq!(ret.params, empty_vec);
println!("/unknwon, {:?}, {:?}", ret.value, ret.params);println!("Done!");
}
```## Contributing
Every contribution is welcomed: Open an issue a fire a PR!
## License
See [License file](./LICENSE)