|
| 1 | +# High-Performance HTTP Server in Rust |
| 2 | + |
| 3 | +This project is a lightweight and high-performance HTTP server written in **Rust**. |
| 4 | +It is designed with modular structure, concurrency, and real-time statistics tracking. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +- Lightweight and minimal dependencies |
| 11 | +- Fast response for core endpoints: |
| 12 | + - `GET /` → returns `"OK"` |
| 13 | + - `GET /stats` → returns JSON with real-time statistics: |
| 14 | + - `total_connections`: number of requests since server start |
| 15 | + - `rps`: requests per second |
| 16 | +- Modular code structure: |
| 17 | + - `server.rs` → manages server lifecycle |
| 18 | + - `routes.rs` → defines HTTP routes |
| 19 | + - `stats.rs` → tracks server statistics |
| 20 | +- Built on **Tokio** and **Hyper** for asynchronous performance |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Project Structure |
| 25 | + |
| 26 | +``` |
| 27 | +src/ |
| 28 | +├─ main.rs # Entry point |
| 29 | +├─ server.rs # HTTP server logic |
| 30 | +├─ routes.rs # Routing and responses |
| 31 | +└─ stats.rs # Real-time statistics |
| 32 | +Cargo.toml # Project configuration |
| 33 | +Makefile # Build and utility commands |
| 34 | +``` |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## Requirements |
| 39 | + |
| 40 | +- Rust (latest stable version recommended) |
| 41 | +- Cargo build system |
| 42 | +- Linux, macOS, or Windows |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## Build and Run |
| 47 | + |
| 48 | +### Build |
| 49 | +```bash |
| 50 | +make build |
| 51 | +``` |
| 52 | + |
| 53 | +### Run |
| 54 | +```bash |
| 55 | +make run |
| 56 | +``` |
| 57 | + |
| 58 | +The server will start by default at: `http://127.0.0.1:8080` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## Usage |
| 63 | + |
| 64 | +- Root endpoint: |
| 65 | + ```bash |
| 66 | + curl http://127.0.0.1:8080/ |
| 67 | + ``` |
| 68 | + Response: |
| 69 | + ``` |
| 70 | + OK |
| 71 | + ``` |
| 72 | + |
| 73 | +- Statistics endpoint: |
| 74 | + ```bash |
| 75 | + curl http://127.0.0.1:8080/stats |
| 76 | + ``` |
| 77 | + Example response: |
| 78 | + ```json |
| 79 | + { |
| 80 | + "total_connections": 42, |
| 81 | + "rps": 7 |
| 82 | + } |
| 83 | + ``` |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## Development |
| 88 | + |
| 89 | +- Format code: |
| 90 | + ```bash |
| 91 | + make fmt |
| 92 | + ``` |
| 93 | +- Run linter: |
| 94 | + ```bash |
| 95 | + make check |
| 96 | + ``` |
| 97 | +- Run tests: |
| 98 | + ```bash |
| 99 | + make test |
| 100 | + ``` |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## License |
| 105 | + |
| 106 | +This project is licensed under the **MIT License**. |
| 107 | +You are free to use, modify, and distribute it under the terms of the license. |
0 commit comments