Amiya
Yet another experimental middleware-based minimalism async HTTP server framework.
Working in progress, just alpha stage now, missing many features.
A Taste
Code:
mod common;
use amiya::{m, Amiya};
fn main() {
let ex = common::global_executor();
let amiya = Amiya::default()
.uses(m!(ctx => {
println!("new request at");
ctx.next().await?;
let content = ctx.resp.take_body().into_string().await.unwrap();
println!("finish, response is: {}", content);
ctx.resp.set_body(content);
Ok(())
}))
.uses(m!(ctx => {
ctx.next().await?;
ctx.resp.set_body("Hello World!");
Ok(())
}));
blocking::block_on(ex.spawn(amiya.listen("[::]:8080"))).unwrap();
}
Log:
$ cargo run --release --example taste
new request
finish, response is: Hello World!
Curl:
$ curl 'http://127.0.0.1:8080/' -v
* Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.71.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< content-length: 12
< date: Thu, 16 Jul 2020 09:50:58 GMT
< content-type: text/plain;charset=utf-8
<
* Connection Hello World!
Examples
See examples
folder for more example with comments.
License
BSD 3-Clause Clear License, See LICENSE
.