Files
blog/posts/rust-web-servers.md
Guus Waals 29502f6816 Initial commit
Initial commit

Add lua template
2025-10-24 19:24:07 +08:00

1.2 KiB

Building Web Servers in Rust

Rust has become a popular choice for building web servers due to its performance and safety guarantees.

Why Rust for Web Development?

  1. Memory Safety: No null pointer exceptions or data races
  2. Performance: Comparable to C/C++
  3. Concurrency: Fearless concurrency with async/await
  4. Type System: Catch errors at compile time

Axum

Axum is a modern web framework built on top of Tokio. It provides:

  • Type-safe routing
  • Extractors for parsing requests
  • Middleware support
  • Great ergonomics

Actix Web

Actix Web is a powerful, pragmatic framework that:

  • Uses the actor model
  • Provides excellent performance
  • Has a mature ecosystem

Rocket

Rocket focuses on:

  • Developer ergonomics
  • Type-safe routing
  • Easy to learn

Example Server

use axum::{routing::get, Router};

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/", get(|| async { "Hello, World!" }));

    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
        .await
        .unwrap();

    axum::serve(listener, app).await.unwrap();
}

This is just the beginning of what you can build with Rust!