#blazingly #memory-safe #parser #http1 #server #http2

altaria

Altaria is an asynchronous, memory-safe, blazingly fast HTTP server written in Rust. It currently supports HTTP1.1 parsing and encoding and HTTP2 parsing.

11 unstable releases (3 breaking)

new 0.4.2 Dec 20, 2024
0.4.1 Dec 19, 2024
0.3.5 Dec 18, 2024
0.2.0 Dec 16, 2024
0.1.301 Dec 7, 2024

#589 in Parser implementations

Download history 305/week @ 2024-12-06 356/week @ 2024-12-13

661 downloads per month

Custom license

73KB
2K SLoC

🌌️ altaria

Altaria is an asynchronous, memory-safe, blazingly fast HTTP server written in Rust.

Roadmap:

  • HTTP1.1 protocol
  • HTTP1.1 parsing
  • HTTP1.1 encoding
  • Routing
  • Resources (states)
  • Json
  • Query parameters
  • Middlewares
  • Websockets
  • HTTP2
  • TLS

[!IMPORTANT]
This project is made mostly for educational/learning purposes. It is not recommended to use it in production. Maybe in the future, it will be production-ready.

struct State(usize);

#[tokio::main]
async fn main() {
    let handler = function_handler(|_| async {
        (HttpStatusCode::OK, "Hello, World!")
    });

    let router = Router::new()
        .add_resource("Altaria")
        .add_resource(Arc::new(Mutex::new(State(0))))
        .add_handler("/", handler)
        .add_endpoint(endpoint!(greet))
        .add_endpoint(endpoint!(count));

    Server::builder()
        .local_port(8080)
        .router(router)
        .start()
        .await
        .unwrap()
}

#[get("/meet/{name}?sec={secret}")]
async fn meet(
    name: String,
    secret: Option<String>,
    Resource(me): Resource<&str>,
) -> String {
    match secret {
        Some(secret) => format!("I'm, {me}! Hello {name}! Your secret is {secret}"),
        _ => format!("I'm, {me}! Hello, {name}!")
    }
}

#[post("/count")]
async fn count(
    Resource(state): Resource<SharedState>,
    JsonBody(update): JsonBody<CountUpdate>
) -> JsonBody<CountUpdate> {
    let mut state = state.lock().await;
    state.count = update.new_count;
    JsonBody(CountUpdate {
        new_count: state.count
    })
}

Dependencies

~5–12MB
~126K SLoC