____ ____ ____ __ __ _ __ ____ ____ _ _ ___ ____
| _ \| _ \| _ \| \/ | | / / | _ \| _ \| | | |/ _ \| _ \
| |_) | |_) | |_) | |\/| | |/ / | |_) | |_) | | | | | | | |_) |
| _ <| __/| _ <| | | | < | __/| _ <| |_| | |_| | _ <
|_| \_\_| |_| \_\_| |_|_|\_\ |_| |_| \_\\___/ \___/|_| \_\
No frameworks. No dependencies. Just pure std.
|
|
💡 New to Rust? Install it from rust-lang.org
# Clone and run in seconds
$ git clone https://github.com/prajjwalkumar17/Basic_server.git
$ cd Basic_server
$ cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.12s
Running `target/debug/basic_server`
🔮 Server listening on http://127.0.0.1:8080
That's it! Your server is now serving requests. 🎉
| Method | Endpoint | Description | Response |
|---|---|---|---|
GET |
/ |
Homepage | 📄 index.html |
GET |
/hello |
Greeting endpoint | 💬 200 OK |
GET |
/hello?name=You |
Personalized greeting | 💬 Hello, You! |
GET |
/* |
Static files | 📁 200/404 |
* |
/* |
Other methods | ❌ 404 |
# 🏠 Homepage
$ curl http://127.0.0.1:8080/
# 👋 Hello endpoint
$ curl http://127.0.0.1:8080/hello
# 🎨 Static assets
$ curl http://127.0.0.1:8080/style.css
# 📝 Query string magic
$ curl "http://127.0.0.1:8080/hello?name=World&greeting=Hola"
# ❓ Missing routes → 404
$ curl -i http://127.0.0.1:8080/nowhere
HTTP/1.1 404 Not Found📦 Basic_server
├── 📄 Cargo.toml # Workspace configuration
├── 📁 crates/
│ ├── 📁 basic_server/ # Binary entry point
│ │ └── 📄 main.rs # Server bootstrap
│ └── 📁 basic_server_lib/ # Core library
│ ├── 📄 server.rs # TCP listener & connections
│ ├── 📄 website_handler.rs # Route logic
│ └── 📁 http/ # HTTP protocol implementation
│ ├── 📄 method.rs # GET, POST, etc.
│ ├── 📄 request.rs # Request parsing
│ ├── 📄 response.rs # Response building
│ ├── 📄 query_string.rs # Query parsing
│ └── 📄 status_code.rs # HTTP status codes
├── 📁 public/ # Static file root
│ ├── 📄 index.html
│ ├── 📄 hello.html
│ └── 📄 style.css
└── 📁 scripts/
└── 📄 test-curls.sh # Integration tests
Run the full test suite with one command:
$ bash ./scripts/test-curls.shWhat it validates:
- ✅
/→ Returns index page (200 OK) - ✅
/hello→ Returns greeting (200 OK) - ✅
/style.css→ Returns CSS (200 OK) - ✅ Invalid routes → Returns
404 Not Found - ✅ Server lifecycle (start, test, cleanup)
| Environment Variable | Default | Description |
|---|---|---|
PUBLIC_PATH |
./public |
Directory for static files |
HOST |
127.0.0.1 |
Server bind address |
PORT |
8080 |
Server port |
$ PUBLIC_PATH=/var/www/static cargo run
🔮 Server listening on http://127.0.0.1:8080
📁 Serving files from: /var/www/static| 🎓 Learning | 🏎️ Performance | 🔒 Security |
|---|---|---|
| Understand HTTP/1.1 protocol internals | Zero overhead from frameworks | Learn about directory traversal attacks |
| See how Rust handles TCP networking | Compile-time optimizations | Implement security from day one |
| Master request/response lifecycle | Minimal memory footprint | Build defensive coding habits |
This project is perfect for:
- 📚 Students learning web server internals
- 🦀 Rustaceans exploring
std::netand TCP - 🔧 Developers who want to understand what frameworks hide
- 🏗️ Builders needing a minimal, dependency-free HTTP server
Contributions are welcome! Here's how to help:
- 🍴 Fork the repository
- 🌿 Create a feature branch (
git checkout -b feature/amazing) - 💾 Commit your changes (
git commit -m 'Add amazing feature') - 📤 Push to the branch (
git push origin feature/amazing) - 🎉 Open a Pull Request
- Follow standard Rust conventions (
cargo fmt) - Add tests for new functionality
- Document public APIs with doc comments
This project is open-sourced under the MIT License.
See LICENSE for the full text.