help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
rust-web-server
RSK World
rust-web-server
Rust Web Server - High-Performance Async Web Server + WebSocket Support + JWT Authentication + File Upload + Memory Safety + Educational Design
rust-web-server
  • .github
  • .vscode
  • benches
  • docs
  • src
  • static
  • tests
  • .dockerignore611 B
  • .editorconfig735 B
  • .env.example676 B
  • .gitignore1.4 KB
  • CHANGELOG.md2 KB
  • CONTRIBUTING.md3.3 KB
  • Cargo.toml1.7 KB
  • Dockerfile1.1 KB
  • LICENSE1.4 KB
  • Makefile2.4 KB
  • README.md7.9 KB
  • SECURITY.md3.2 KB
  • clippy.toml946 B
  • config.toml.example1.3 KB
  • docker-compose.yml380 B
  • rustfmt.toml1.5 KB
README.md
README.md
Raw Download

README.md

# ๐Ÿฆ€ Rust Web Server

High-performance web server built with Rust, featuring async request handling, memory safety, concurrent connections, and static file serving.

## ๐Ÿ“‹ Project Details

- **Title**: Rust Web Server
- **Category**: Rust Projects
- **Difficulty**: Advanced
- **Author**: RSK World
- **Year**: 2026

## ๐Ÿš€ Features

- โœ… **High Performance**: Built with Rust's async/await and Tokio runtime
- โœ… **Memory Safety**: Rust's ownership system prevents common memory bugs
- โœ… **Concurrent Connections**: Handle multiple requests simultaneously
- โœ… **Static File Serving**: Efficiently serve static files with proper MIME types
- โœ… **RESTful API**: Built-in API endpoints for server information and statistics
- โœ… **Error Handling**: Comprehensive error handling with proper HTTP status codes
- โœ… **Security**: Security headers and input validation
- โœ… **Logging**: Structured logging with tracing
- โœ… **Configuration**: Flexible configuration system
- โœ… **Middleware**: Request/response middleware support

## ๐Ÿ› ๏ธ Technologies Used

- **Rust** - Systems programming language
- **Tokio** - Asynchronous runtime
- **Hyper** - HTTP server implementation
- **Serde** - Serialization/deserialization
- **Tracing** - Structured logging
- **Async/Await** - Asynchronous programming
- **HTTP Server** - Web server functionality
- **Memory Safety** - Rust's safety guarantees
- **Concurrency** - Multi-threaded request handling

## ๐Ÿ“ฆ Installation

### Prerequisites

- Rust 1.70+ installed
- Cargo package manager

### Build from Source

```bash
# Clone the repository
git clone <repository-url>
cd rust-web-server

# Build the project
cargo build --release

# Run the server
cargo run --release
```

### Run with Custom Configuration

```bash
# Custom port and host
cargo run --release -- --port 3000 --host 0.0.0.0

# Custom static files directory
cargo run --release -- --static-dir ./public

# Custom number of worker threads
cargo run --release -- --workers 8
```

## ๐ŸŽฏ Usage

### Command Line Options

```bash
rust-web-server [OPTIONS]

OPTIONS:
-h, --help Print help information
-p, --port <PORT> Port to listen on [default: 8080]
-H, --host <HOST> Host to bind to [default: 127.0.0.1]
-s, --static-dir <DIR> Path to static files directory [default: static]
-w, --workers <WORKERS> Number of worker threads [default: 4]
```

### API Endpoints

#### GET `/`
Returns the home page with server information and available endpoints.

#### GET `/health`
Health check endpoint that returns server status.

**Response:**
```json
{
"status": "healthy",
"timestamp": "2026-01-23T10:00:00Z",
"uptime_seconds": 3600,
"active_connections": 5
}
```

#### GET `/api/info`
Returns detailed server information.

**Response:**
```json
{
"name": "Rust Web Server",
"version": "0.1.0",
"description": "High-performance web server built with Rust",
"author": "RSK World",
"contact": {
"website": "https://rskworld.in",
"email": "hello@rskworld.in",
"phone": "+91 93305 39277",
"address": "Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147"
},
"features": [
"High performance",
"Async request handling",
"Memory safety",
"Concurrent connections",
"Static file serving",
"Systems programming"
],
"technologies": [
"Rust",
"Tokio",
"Async/Await",
"HTTP Server",
"Memory Safety",
"Concurrency"
]
}
```

#### GET `/api/stats`
Returns server statistics and performance metrics.

**Response:**
```json
{
"uptime_seconds": 3600,
"request_count": 1250,
"active_connections": 5,
"memory_usage_mb": 42.0,
"cpu_usage_percent": 15.2
}
```

#### POST `/api/echo`
Echo service that returns the request data.

**Request:**
```json
{
"message": "Hello, World!"
}
```

**Response:**
```json
{
"message": "Hello, World!",
"timestamp": "2026-01-23T10:00:00Z",
"method": "POST",
"path": "/api/echo",
"headers": {
"content-type": "application/json",
"user-agent": "curl/7.68.0"
}
}
```

#### Static File Serving
Static files are served from the configured static directory (default: `static`).

- `GET /static/*` - Serve static files
- `GET /` - Serves `index.html` if it exists in the static directory

## ๐Ÿ—๏ธ Project Structure

```
rust-web-server/
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ main.rs # Main server entry point
โ”‚ โ”œโ”€โ”€ config.rs # Configuration management
โ”‚ โ”œโ”€โ”€ error.rs # Error handling types
โ”‚ โ”œโ”€โ”€ handlers.rs # Request handlers
โ”‚ โ”œโ”€โ”€ middleware.rs # Middleware functions
โ”‚ โ”œโ”€โ”€ static_files.rs # Static file serving
โ”‚ โ””โ”€โ”€ utils.rs # Utility functions
โ”œโ”€โ”€ static/ # Static files directory
โ”œโ”€โ”€ Cargo.toml # Dependencies and project config
โ””โ”€โ”€ README.md # This file
```

## ๐Ÿ”ง Configuration

The server can be configured via command-line arguments or configuration files.

### Environment Variables

- `RUST_LOG` - Set logging level (e.g., `RUST_LOG=info`)
- `HOST` - Default host to bind to
- `PORT` - Default port to listen on
- `STATIC_DIR` - Default static files directory

### Configuration File (TOML)

Create a `config.toml` file:

```toml
host = "127.0.0.1"
port = 8080
static_dir = "static"
workers = 4
max_connections = 1000
request_timeout_secs = 30
buffer_size = 8192
```

## ๐Ÿงช Testing

Run the test suite:

```bash
# Run all tests
cargo test

# Run tests with output
cargo test -- --nocapture

# Run specific test
cargo test test_server_info
```

## ๐Ÿ“Š Performance

The server is designed for high performance:

- **Async I/O**: Non-blocking request handling
- **Memory Safety**: No garbage collection overhead
- **Zero-cost Abstractions**: Rust's performance guarantees
- **Concurrent Processing**: Multi-threaded request handling

### Benchmark Results

- **Requests per second**: ~50,000+ (simple GET requests)
- **Memory usage**: ~10-50MB base memory
- **Latency**: <1ms for static files
- **Concurrent connections**: 1000+ simultaneous connections

## ๐Ÿ”’ Security Features

- **Input Validation**: Request size limits and path validation
- **Security Headers**: XSS protection, content type options, etc.
- **CORS Support**: Configurable cross-origin resource sharing
- **Rate Limiting**: Basic rate limiting implementation
- **Path Traversal Protection**: Prevents directory traversal attacks

## ๐Ÿ“ Logging

The server uses structured logging with tracing:

```bash
# Set log level
RUST_LOG=debug cargo run

# Log to file
RUST_LOG=info cargo run 2>&1 | tee server.log
```

## ๐Ÿค Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Submit a pull request

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ‘ฅ Author

**RSK World**

- **Founder**: Molla Samser
- **Designer & Tester**: Rima Khatun
- **Website**: https://rskworld.in
- **Email**: hello@rskworld.in, support@rskworld.in
- **Phone**: +91 93305 39277
- **Address**: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147

## ๐Ÿ“ž Contact

For support, questions, or contributions:

- ๐Ÿ“ง **Email**: hello@rskworld.in
- ๐Ÿ“ฑ **Phone**: +91 93305 39277
- ๐ŸŒ **Website**: https://rskworld.in
- ๐Ÿ“‹ **Contact Form**: https://rskworld.in/contact.php

## ๐Ÿ™ Acknowledgments

- The Rust community for excellent documentation and tools
- Tokio team for the amazing async runtime
- Hyper team for the robust HTTP implementation

---

**ยฉ 2026 RSK World. All rights reserved.**

*Content used for educational purposes only.*

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer