Skip to content

Building an HTTP server from scratch

License

Swap-nagras/http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Server from Scratch

A lightweight HTTP server implemented in pure Java without any external dependencies. This project demonstrates low-level networking, HTTP protocol handling, and concurrent programming concepts.

Features

  • Custom TCP socket implementation
  • HTTP/1.1 protocol support
  • Multithreaded request handling
  • Static file serving
  • Custom routing system
  • Support for GET and POST methods
  • Basic request/response logging

Project Structure

src/
├── main/
│   └── java/
│       └── com/
│           └── httpserver/
│               ├── core/
│               │   ├── HttpServer.java       # Main server class
│               │   ├── RequestHandler.java   # Handles client connections
│               │   └── ServerConfig.java     # Server configuration
│               ├── http/
│               │   ├── HttpRequest.java      # HTTP request parser
│               │   ├── HttpResponse.java     # HTTP response builder
│               │   └── HttpHeaders.java      # HTTP headers utility
│               ├── router/
│               │   ├── Router.java          # Request routing
│               │   └── Route.java           # Route definition
│               └── Main.java                # Entry point
└── resources/
    └── static/                              # Static files directory
        └── index.html

Getting Started

  1. Clone the repository
  2. Run javac src/main/java/com/httpserver/Main.java
  3. Run java src.main.java.com.httpserver.Main
  4. Server will start on port 8080 (configurable)

Usage Examples

# GET request
curl http://localhost:8080/hello

# POST request
curl -X POST -d "message=hello" http://localhost:8080/echo

# Serve static file
curl http://localhost:8080/index.html

About

Building an HTTP server from scratch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published