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.