std web_server
A multi-threaded HTTP server written with the Rust standard library only: thread pool, TCP listener and static file serving.
A minimal but functional multi-threaded web server implemented entirely with the Rust standard library. No external dependencies, just pure std.
Built with rust 1.83.0.
The server shows how to build a basic concurrent HTTP server using only the Rust Standard Library. It covers file I/O, networking, threading and concurrency.
It suits systems programmers, backend developers exploring Rust, and students building web server fundamentals.
Tech stack, std only
The server is powered by a thread pool and handles each TCP connection using:
fs, for serving static HTML filesnet::{TcpListener, TcpStream}, for socket connectionsthread, to spawn workerssync::{mpsc, Arc, Mutex}, for shared message passingtime::Duration, for simulated delays (e.g. thread sleeping)io::{BufReader, prelude::*}, to read and parse incoming streams
Features
- Multi-threaded request handling. A built-in thread pool handles requests concurrently.
- Graceful connection handling. Reads HTTP headers via
BufReaderand routes based on request paths. - Static file serving. Serves
.htmlfiles directly from the filesystem. - Clean shutdown mechanism. Graceful shutdown via message passing.
- Zero dependencies. Uses only what
stdoffers, which is a good way to see how the pieces work under the hood.
Project structure
main.rs, entry point, sets up the listener and the thread poollib.rs, contains the thread pool implementationstatic/, 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 the 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 an async runtime by comparing with
tokiolater
License
This project is licensed under the MIT License. Feel free to build on it, fork it, or turn it into something bigger.
Neighbors in time
Related: the posts that share this one's subject, and where the thread goes next.