Security-first, high-performance, zero-allocation HTTP server for microservices
I started maker_web without a clear plan, simply wanting to create something useful. The result is a tool that embodies freedom, speed, and security. I don't strive for "convenience" at the expense of freedom. And I love how it turned out.
You'll see the PHILOSOPHY.md file in the project soon :)
use maker_web::{Handled, Handler, Request, Response, Server, StatusCode};
use tokio::net::TcpListener;
struct HelloWorld;
impl Handler for HelloWorld {
async fn handle(&self, _: &mut (), _: &Request, resp: &mut Response) -> Handled {
resp.status(StatusCode::Ok)
.header("Content-Type", "text/plain")
.body("Hello, world!")
}
}
#[tokio::main]
async fn main() {
Server::builder()
.listener(TcpListener::bind("127.0.0.1:8080").await.unwrap())
.handler(HelloWorld)
.build()
.launch()
.await;
}
use maker_web::{Handled, Handler, Request, Response, Server, StatusCode};
use tokio::net::TcpListener;
struct MyHandler;
impl Handler for MyHandler {
async fn handle(&self, _: &mut (), req: &Request, resp: &mut Response) -> Handled {
match req.url().path_segments_str() {
["api", user, "name"] => {
resp.status(StatusCode::Ok).body(user)
}
["api", user, "name", "len"] => {
resp.status(StatusCode::Ok).body(user.len())
}
["api", "echo", text] => {
resp.status(StatusCode::Ok).body(text)
}
_ => resp.status(StatusCode::NotFound).body("qwe"),
}
}
}
#[tokio::main]
async fn main() {
Server::builder()
.listener(TcpListener::bind("127.0.0.1:8080").await.unwrap())
.handler(MyHandler)
.build()
.launch()
.await;
}