Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Python HTTP Server

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.

πŸš€ Features

  • Creates a TCP socket using Python's socket module
  • Binds the server to a host and port
  • Listens for incoming TCP connections
  • Accepts client connections
  • Receives and parses basic HTTP requests
  • Supports the GET method
  • Serves HTML files
  • Serves JSON data
  • Returns a custom 404 page for unknown routes
  • Returns 405 Method Not Allowed for unsupported HTTP methods

πŸ› οΈ Technologies

  • Python 3
  • TCP Sockets
  • HTTP/1.1
  • HTML
  • JSON

πŸ“ Project Structure

python-http-server/
β”‚
β”œβ”€β”€ main.py
β”œβ”€β”€ index.html
β”œβ”€β”€ data.json
β”œβ”€β”€ not_found.html
└── README.md

How It Works

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

Example Request

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.

▢️ Running the Server

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.

🎯 Purpose

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.

About

A lightweight HTTP server built from scratch in Python using TCP sockets to explore HTTP, networking, and backend fundamentals.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages