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
//! A simple and fast webserver.
//!
//! `crane-webserver` proves the tools you need to quickly build
//! a webserver.
//!
//! # How it works?
//!
//! At its core, `crane-webserver` contains a `WebServer`.
//! The `WebServer` is a "builder", which takes a closure
//! which is responsible for mapping different functions for
//! different paths, then call the `start` function
//! to start the web server.
//!
//! # Examples
//!
//! A basic web server that serves "Hello, World!"
//! ```rust
//! use crane_webserver::webserver::WebServer;
//!
//! fn main() {
//! let server = WebServer::bind("127.0.0.1:8888", |path, _query| {
//! match path.as_str() {
//! "/" => root()
//! _ => ResponseBuilder::new().build()
//! }
//! }).unwrap();
//!
//! server.start();
//! }
//!
//! fn root() -> Response {
//! ResponseBuilder::new()
//! .status(HttpStatus::OK)
//! .header("Content-Type", "text/plain")
//! .body("Hello, World!")
//! .build()
//! }
//! ```
//!
//! Run the program and then open your web browser
//! goto `http://localhost:8888/` and see the server in action!
pub use WebServer;
pub use ;
pub use HttpStatus;
pub
pub
pub
pub type Query = HashMap;
// TODO: use environment variable
pub const NUM_THREADS: u32 = 4;