outfall

Crates.iooutfall
lib.rsoutfall
version0.0.1
sourcesrc
created_at2024-11-18 16:56:05.179022
updated_at2024-11-18 16:56:05.179022
descriptionExperimental low-level HTTP Library for Rust
homepage
repositoryhttps://github.com/RomanEmreis/outfall
max_upload_size
id1452394
size27,861
Roman (RomanEmreis)

documentation

README

outfall

Experimental low-level HTTP Library for Rust

CI

Getting Started

[dependencies]
outfall = "0.0.1"
tokio = "1.41.1"
use std::io::Error;
use tokio::io;
use tokio::net::TcpListener;
use outfall::server::http1;
use bytes::Bytes;
use http::{
    Request, 
    Response
};

async fn request_handler(_req: Request<Bytes>) -> io::Result<Response<Bytes>> {
    Response::builder()
        .status(200)
        .body("Hello World!".into())
        .map_err(|_| Error::new(io::ErrorKind::Other, "Unable to create a response"))
}

#[tokio::main]
async fn main() -> io::Result<()> {
    let tcp_listener = TcpListener::bind("127.0.0.1:7878").await?;

    loop {
        let (stream, _) = tcp_listener.accept().await?;

        tokio::spawn(async move {
            let conn = http1::Connection::new(stream);
            conn.run(request_handler).await;
        });
    }
}
Commit count: 9

cargo fmt