1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//!A light HTTP framework with REST-like features. The main purpose of Rustful
//!is to create a simple, modular and non-intrusive foundation for HTTP
//!applications. It has a mainly stateless structure, which naturally allows
//!it to run both as one single server and as multiple instances in a cluster.
//!
//!A new server is created using the [`Server`][server] type, which contains
//!all the necessary settings as fields:
//!
//!```no_run
//!#[macro_use]
//!extern crate rustful;
//!use rustful::{Server, Handler, Context, Response, TreeRouter};
//!
//!struct Greeting(&'static str);
//!
//!impl Handler for Greeting {
//! fn handle_request(&self, context: Context, response: Response) {
//! //Check if the client accessed /hello/:name or /good_bye/:name
//! if let Some(name) = context.variables.get("name") {
//! //Use the value of :name
//! response.send(format!("{}, {}", self.0, name));
//! } else {
//! response.send(self.0)
//! }
//! }
//!}
//!
//!# fn main() {
//!let my_router = insert_routes!{
//! //Create a new TreeRouter
//! TreeRouter::new() => {
//! //Receive GET requests to /hello and /hello/:name
//! "hello" => {
//! Get: Greeting("hello"),
//! ":name" => Get: Greeting("hello")
//! },
//! //Receive GET requests to /good_bye and /good_bye/:name
//! "good_bye" => {
//! Get: Greeting("good bye"),
//! ":name" => Get: Greeting("good bye")
//! }
//! }
//!};
//!
//!Server {
//! //Use a closure to handle requests.
//! handlers: my_router,
//! //Set the listening port to `8080`.
//! host: 8080.into(),
//! //Fill out everything else with default values.
//! ..Server::default()
//!}.run();
//!# }
//!```
//!
//![server]: server/struct.Server.html
extern crate test;
extern crate rustc_serialize;
extern crate multipart;
extern crate url;
extern crate time;
extern crate hyper;
extern crate anymap;
extern crate phf;
extern crate num_cpus;
pub use mime;
pub use Method;
pub use StatusCode;
pub use header;
pub use Result as HttpResult;
pub use Error as HttpError;
pub use HttpVersion;
pub use Server;
pub use Context;
pub use Response;
pub use Error;
pub use Handler;
pub use Router;
pub use TreeRouter;