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
//! # toy-rusttp
//!
//! A small, synchronous http server library with a surprisingly pleasant
//! developer experience and minimal moving parts.
//!
//! ## Example usage:
//!
//! ```no_run
//! use torus_http::prelude::*;
//!
//! fn main() {
//! let server: HttpServer = HttpServer::new()
//! .get("/", hello_world)
//! .route(
//! "/hello",
//! HttpMethod::other("custom"),
//! |_| "hello from a custom method",
//! )
//! .add_middleware(|req| {
//! println!("got request: {req:#?}");
//! req
//! });
//!
//! server
//! .listen(("127.0.0.1", 8080))
//! .expect("Failed listening...");
//! }
//!
//! pub fn hello_world(req: HttpRequest) -> impl Response {
//! HttpResponse::new()
//! .set_body(format!(
//! "<h1>hey there from torus!</h1><p>this is a test, your request is: {req:#?}</p>",
//! ))
//! .insert_header("Content-Type", "text/html")
//! }
//! ```