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
RequestHandlerinterface - Request parsing (method, path, headers, body)
- Response builder with support for multiple formats
- A complete class diagram for architecture visibility
The server listens on a configurable port and processes each incoming socket by:
- Parsing the HTTP request into a
Requestobject - Passing it to the
Router - Resolving the appropriate
RequestHandlerviaRoutes - Building the HTTP response with
Responsehelpers - Sending the result back through the socket
The structure is intentionally simple so you can extend it β adding controllers, middleware, or even template rendering.
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
Below is a full Mermaid UML diagram representing the architecture:
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
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