Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Multi-Threaded Web Server

A multi-threaded web server implementation in Rust, built as an enhanced version of the final project from The Rust Programming Language Book.

Overview

This project extends the book's single-threaded web server into a multi-threaded version using Rust's thread pool pattern. It demonstrates concurrent connection handling while maintaining thread safety.

Features

  • Multi-threaded request handling using a thread pool
  • Graceful shutdown capability
  • HTTP/1.1 GET request support
  • Static file serving from local directory
  • Configurable number of worker threads
  • Proper HTTP status codes (200, 404)
  • Thread-safe resource access

Getting Started

Prerequisites

  • Rust 1.65+ (for Arc and Mutex improvements)
  • Cargo
  • Basic understanding of concurrency in Rust

Installation

  1. Clone the repository:
git clone https://github.com/your-username/rust-multi-threaded-server.git
cd rust-multi-threaded-server
  1. Build the project:
cargo build --release

Usage

  1. Run the server (defaults to 4 threads):
cargo run --release
  1. Access endpoints in your browser or via curl:
Endpoint Description Example Command
/ Default "Hello Page" curl http://127.0.0.1:7878
/sleep Simulates slow processing (5s delay) curl http://127.0.0.1:7878/sleep
Any other path 404 Not Found page curl http://127.0.0.1:7878/test
  1. Try concurrent requests to test threading:

In one terminal:

curl http://127.0.0.1:7878/sleep

In another terminal (should respond immediately):

curl http://127.0.0.1:7878

About

A multi-threaded web server implementation in Rust, built as an enhanced version of the final project from The Rust Programming Language Book.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages