EzHttp
Easy http server for small sites
This library is under developement, so if you found any bugs, please write them to Issues
Setup
ezhttp = "0.2.0"
ezhttp = { git = "https://github.com/MeexReay/ezhttp" }
Examples
Hello world example:
use ezhttp::prelude::*;
struct EzSite(String);
impl HttpServer for EzSite {
async fn on_request(&self, req: &HttpRequest) -> Option<HttpResponse> {
println!("{} > {} {}", req.addr, req.method, req.url.to_path_string());
if req.url.path == "/" {
Some(HttpResponse::new(
OK, Headers::from(vec![ ("Content-Type", "text/html"), ("Content-Length", self.0.len().to_string().as_str()) ]), Body::from_text(&self.0.clone()), ))
} else {
None }
}
async fn on_start(&self, host: &str) {
println!("Http server started on {}", host);
}
async fn on_close(&self) {
println!("Http server closed");
}
}
#[tokio::main]
async fn main() {
start_server(EzSite("Hello World!".to_string()), "localhost:8080").await.expect("http server error");
}
More examples
Contributing
If you would like to contribute to the project, feel free to fork the repository and submit a pull request.
License
This project is licensed under the WTFPL License