https://github.com/barcellos-pedro/java-http-server
Simple Web Server with zero dependencies. From TCP to HTTP.
https://github.com/barcellos-pedro/java-http-server
http java server study tcp
Last synced: about 1 month ago
JSON representation
Simple Web Server with zero dependencies. From TCP to HTTP.
- Host: GitHub
- URL: https://github.com/barcellos-pedro/java-http-server
- Owner: barcellos-pedro
- Created: 2025-11-23T04:42:40.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2026-01-29T01:43:14.000Z (5 months ago)
- Last Synced: 2026-01-29T17:18:33.007Z (5 months ago)
- Topics: http, java, server, study, tcp
- Language: Java
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Java HTTP Server
This project implements a minimal, educational HTTP server in Java.
The goal is to understand low-level request handling, routing, controllers, and response building without relying on large frameworks.
It includes:
- Socket-based HTTP server
- Basic router and mapping system
- Controllers implementing a `RequestHandler` interface
- Request parsing (method, path, headers, body)
- Response builder with support for multiple formats
- A complete class diagram for architecture visibility
---
## π Overview
The server listens on a configurable port and processes each incoming socket by:
1. Parsing the HTTP request into a `Request` object
2. Passing it to the `Router`
3. Resolving the appropriate `RequestHandler` via `Routes`
4. Building the HTTP response with `Response` helpers
5. Sending the result back through the socket
The structure is intentionally simple so you can extend it β adding controllers, middleware, or even template rendering.
---
## π¦ Project Structure
```text
java-echo-server/
βββ README.md
βββ src
βΒ Β βββ main
βΒ Β βββ java
βΒ Β βββ com
βΒ Β βββ server
βΒ Β βββ controller
βΒ Β βΒ Β βββ EchoController.java
βΒ Β βΒ Β βββ GreetingController.java
βΒ Β βΒ Β βββ NotFoundController.java
βΒ Β βΒ Β βββ RequestHandler.java
βΒ Β βββ http
βΒ Β βΒ Β βββ HttpMethod.java
βΒ Β βΒ Β βββ HttpServer.java
βΒ Β βΒ Β βββ Request.java
βΒ Β βΒ Β βββ Response.java
βΒ Β βββ Main.java
βΒ Β βββ router
βΒ Β βΒ Β βββ Router.java
βΒ Β βΒ Β βββ Routes.java
βΒ Β βββ utils
βΒ Β βββ ResponseTemplate.java
βββ tests
βββ load_get_greeting.sh
βββ load_post_message.sh
βββ run_all_load_tests.sh
```
## π§© Class Diagram
Below is a full Mermaid UML diagram representing the architecture:
```mermaid
sequenceDiagram
autonumber
participant Client
participant HttpServer
participant Router
participant Routes
participant Controller
participant Response
Client ->> HttpServer: HTTP request
HttpServer ->> Router: handle(socket)
Router ->> Routes: getOrNotFound(request)
Routes -->> Router: handler
Router ->> Controller: handle(request)
Controller -->> Router: body
Router ->> Response: build response
Response -->> Router: http string
Router -->> Client: http response
```
## π§±Architecture Overview
```mermaid
flowchart LR
Client["Client(curl / browser)"]
subgraph Server["Java Echo Server"]
HttpServer["HttpServer(Socket listener)"]
Router["Router(Request dispatcher)"]
Routes["Routes(Path β Handler mapping)"]
subgraph Controllers
Greeting["GreetingController"]
Echo["EchoController"]
NotFound["NotFoundController"]
end
subgraph HTTP
Request["Request(Parsed HTTP)"]
Response["Response(HTTP builder)"]
Templates["ResponseTemplate"]
end
end
Client --> HttpServer
HttpServer --> Router
Router --> Request
Router --> Routes
Routes --> Greeting
Routes --> Echo
Routes --> NotFound
Router --> Response
Response --> Templates
Response --> Client
```