Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeremyletang/web_dispatcher
Experiment with syntax extensions and web routes dispatch
https://github.com/jeremyletang/web_dispatcher
Last synced: about 1 month ago
JSON representation
Experiment with syntax extensions and web routes dispatch
- Host: GitHub
- URL: https://github.com/jeremyletang/web_dispatcher
- Owner: jeremyletang
- License: mit
- Created: 2014-05-02T16:06:08.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-07T08:33:04.000Z (over 10 years ago)
- Last Synced: 2024-10-22T07:06:50.681Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 607 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
web_dispatcher [![Build Status](https://travis-ci.org/jeremyletang/web_dispatcher.svg?branch=master)](https://travis-ci.org/jeremyletang/web_dispatcher)
==============Experiments with syntax extensions and web routes dispatch
__web_dispatcher__ consist of a set of two libraries:
* `libroute_macros` a syntax extension library to handle routes
* `libweb_dispatcher` the web_dispatcher to dispatch routesThe syntax extension provide new attributes to retrieve data at compile time:
* `#[route = "/home"]` allow users to associate a route to a function
* `#[method = "GET"]` allow users to associate a given method to access the routesexample
=======Here is a simple example of what am i doing:
```Rust
//! simple routes example
#![feature(phase)]#[phase(plugin, link)]
extern crate route_macros;
extern crate web_dispatcher;use std::collections::HashMap;
use web_dispatcher::{Dispatcher, WebParams, Resp, Filled} ;#[route = "/some/*/strange/:age/route"]
pub fn default(p: HashMap, _: ()) -> Resp {
Filled(format!("The name is: {} and the age is {}",
p.to_string("name"),
p.to_int("age")))
}fn main() {
// Create and fill the webparams
let mut params = HashMap::new();
params.insert("name".to_string(), "Paul".to_string());// Create the web_dispatcher and initialize it with routes
let mut dispatcher = Dispatcher::::new(routes!());// Dispatch and store the result
let return_value = dispatcher.run("/some/really/strange/42/route", params);// print the response
println!("{}", return_value.unwrap())
}```
limits
======For the moment you can use only one prototype for all your programm when you use `libroute_macros`.
The web dispatcher is really naive for the moment, and can only handle routes using this kinds
of functions: `fn(HashMap, Box) -> Resp`.