A minimal HTTP server built from scratch in Python using the built-in socket module.
The goal of this project was to understand how HTTP communication works underneath frameworks like FastAPI, Flask, and Express by implementing the basic client-server communication manually.
- Creates a TCP socket using Python's
socketmodule - Binds the server to a host and port
- Listens for incoming TCP connections
- Accepts client connections
- Receives and parses basic HTTP requests
- Supports the
GETmethod - Serves HTML files
- Serves JSON data
- Returns a custom
404page for unknown routes - Returns
405 Method Not Allowedfor unsupported HTTP methods
- Python 3
- TCP Sockets
- HTTP/1.1
- HTML
- JSON
python-http-server/
│
├── main.py
├── index.html
├── data.json
├── not_found.html
└── README.md
The server uses Python's socket module to communicate directly with clients over TCP.
The basic flow is:
Client / Browser
↓
TCP Connection
↓
socket.accept()
↓
Receive HTTP Request
↓
Parse HTTP Method & Path
↓
Determine Resource
↓
Build HTTP Response
↓
Send Response
↓
Close Connection
When visiting:
http://localhost:8080/
the browser sends an HTTP request similar to:
GET / HTTP/1.1
Host: localhost:8080
The server extracts:
Method → GET
Path → /
and serves index.html.
Similarly:
/data
serves data.json.
Any unknown path serves not_found.html.
Make sure Python is installed.
Clone the repository:
git clone https://github.com/itisrudraa/python-http-server.git
cd python-http-server
Run the server:
python main.py
You should see:
Listening to 8080 ...
Then open:
http://localhost:8080
in your browser.
The main purpose of this project is learning.
Instead of starting with a framework and hiding the networking layer behind abstractions, this project explores what happens underneath a basic web server.
Built from scratch to understand the fundamentals of HTTP and backend development.