🌐 std web_server

Minimal yet functional multi-threaded web server implemented entirely using the Rust standard library. No external dependencies β€” just pure std.


πŸ“š GitHub Repository Rust Version

This project demonstrates how to build a basic but concurrent HTTP server by leveraging only the Rust Standard Library.
It serves as a deep dive into Rust’s core capabilities around file I/O, networking, threading, and concurrency.

An excellent hands-on learning example for:

  • Systems programmers
  • Backend developers exploring Rust
  • Students building web server fundamentals

πŸ›  Tech Stack – std Only

The server is powered by a thread pool and handles each TCP connection asynchronously using:

  • πŸ“‚ fs – for serving static HTML files
  • πŸ”— net::{TcpListener, TcpStream} – for socket connections
  • 🧡 thread – to spawn workers
  • πŸ“¦ sync::{mpsc, Arc, Mutex} – for shared message passing
  • πŸ•’ time::Duration – for simulated delays (e.g., thread sleeping)
  • πŸ“– io::{BufReader, prelude::*} – to read and parse incoming streams

✨ Features

  1. Multi-threaded request handling

  2. Built-in thread pool to handle requests concurrently.

  3. Graceful connection handling

  4. Supports reading HTTP headers via BufReader and routing based on request paths.

  5. Static file serving

  6. Can serve .html files directly from the filesystem.

  7. Clean shutdown mechanism

  8. Implements graceful shutdown via message passing.

  9. Zero dependencies

  10. Uses only what std offers β€” perfect for understanding how things work under the hood.


πŸ“‚ Project Structure

  • main.rs – entry point, sets up listener and thread pool
  • lib.rs – contains thread pool implementation
  • static/ – directory for HTML files (index.html, 404.html, etc.)

πŸ§ͺ Example Usage

cargo run

Then open your browser and go to: http://localhost:7878

To simulate a delayed response:

  • Access route /sleep β€” one thread will sleep for 5 seconds.

🧠 Educational Value

This project mirrors the concepts from "The Rust Programming Language" book (Chapter 20), but it goes further with:

  • Better thread pool abstraction
  • Error handling improvements
  • Project-ready formatting

Use it to:

  • Learn how a basic HTTP server works
  • Build custom functionality (routes, MIME types, logging, etc.)
  • Extend toward async runtime by comparing with tokio later

πŸ“„ License

This project is licensed under the MIT License β€” feel free to build on it, fork it, or turn it into something bigger.