A lightweight HTTP server implementation written from scratch in Python. This project demonstrates the core concepts of web servers and HTTP protocol implementation while providing a functional server that can handle both static and dynamic content.
- Built from scratch using Python's socket programming
- Handles both GET and POST requests
- Serves static content (files, images, etc.)
- Dynamic routing with controller-based architecture
- JSON response support
- Configurable content types
- Error handling with appropriate HTTP status codes
I have wrote a detailed blog on this incase if you interested in making this project from scratch with understanding
.
├── server.py # Main server implementation
├── request_parser.py # HTTP request parsing
├── response_builder.py # HTTP response construction
├── response_dispatcher.py # Response handling
├── static_content_provider.py # Static file serving
├── http_status.py # HTTP status codes
├── startup.py # Server initialization
├── controllers/ # Request handlers
├── static/ # Static content directory
└── appsettings.json # Server configuration
- Python 3.x
- Basic understanding of HTTP protocol
- Clone the repository:
git clone https://github.com/yourusername/simple-http-server.git
cd simple-http-server
- Run the server:
python server.py
The server will start listening on 0.0.0.0:8000
by default.
The server supports:
- Static file serving from the
static/
directory - Dynamic routes through controllers
- JSON responses for API endpoints
- Basic error handling
- HTML page:
GET http://localhost:8000/static/home.html
- Image file:
GET http://localhost:8000/static/mobile_phone.png
- Get all users:
GET http://localhost:8000/users
- Add a new user:
POST http://localhost:8000/users
{ "name": "John Doe", "age": "25", "city": "New York" }
Contributions are welcome! This project is open for improvements and new features. Here's how you can contribute:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
- Database integration
- Move configurable parts outside of code into a config file
- HTTPS support
- Request validation
- Authentication and authorization
- CORS support
- Rate limiting
- Documentation improvements
- Transform this project into a reusable framework and library
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
- Built for educational purposes to understand HTTP server implementation
- Inspired by Joao Ventura's blog