Craft is a lightweight HTTP framework.
Status: proof-of-concept
Add this to your application's Cargo.toml
.
sh
[dependencies]
craft = "0.1.0"
```rust use craft; use hyper::*;
fn hello(_request: &Request) -> Response { Response::new(Body::from("Hello, World!")) }
async fn main() { let config = craft::Config::new("127.0.0.1", 3000);
let mut handler_stack = craft::Stack::empty();
handler_stack.set(hello);
craft::get("/hello", handler_stack);
craft::start(&config).await;
} ```
Craft takes a modular-first approach to middlewares ```rust use craft; use hyper::*;
fn firsthandler(request: &Request, next: &dyn Fn() -> Response) -> Response { println!("begin firsthandler"); let response = next(); println!("end firsthandler"); response }
fn secondhandler(request: &Request, next: &dyn Fn() -> Response) -> Response { println!("begin secondhandler"); let response = next(); println!("end secondhandler"); response }
fn hello(_request: &Request) -> Response { Response::new(Body::from("Hello, World!")) }
async fn main() { let config = craft::Config::new("127.0.0.1", 3000); let mut handlerstack = craft::Stack::empty(); handlerstack.push(firsthandler); handlerstack.push(secondhandler); handlerstack.set(hello); craft::get("/hello", handler_stack); craft::start(&config).await; } ```
```sh $ cargo +nightly run --example hello $ cargo +nightly run --example multi_handler
$ curl -X GET localhost:3000/hello Hello, World! ```