How diegcard/arep_taller_1 works
Project Type and Purpose
• This is a lightweight full-stack HTTP server implemented from scratch in pure Java.
• It serves two main roles:
• Static web front-end (HTML/CSS/JS) for a demo interface
• REST API endpoints (/api/hello, /api/weather, /api/quote)
Top-Level Components
1. Client (Browser)
• Loads index.html, styles.css, app.js
• Makes HTTP requests to static assets and REST endpoints via JavaScript
2. HttpServer (Java Application on port 35000)
Internally subdivided into:
a. Connection Listener
• Accepts incoming TCP connections
b. Request Parser & Router
• Parses HTTP/1.1 requests
• Routes to either Static File Service or API Service
c. Static File Service
• MIME Type Detector (maps extensions to Content-Type)
• Cache Manager (in-memory file cache)
• File System Reader (serves files from src/main/resources/static/)
d. API Service
• Handles endpoints:
• GET /api/hello?name={name}
• GET /api/weather
• GET /api/quote
• Builds JSON responses
e. Response Writer
• Constructs HTTP responses with status, headers, body
3. File System / Resource Store
• src/main/resources/static (HTML, CSS, JS, images)
4. Tests
• HttpServerTest.java validating parser, mime detection, endpoints, error cases
Relationships & Data Flows
• Client → HttpServer (HTTP request)
• Branch in server:
– If request path begins “/api/” → API Service → Response Writer → Client
– Else → Static File Service (Cache → File System) → Response Writer → Client
• Static File Service ↔ Cache Manager ↔ File System
• Request Parser → Router → Appropriate handler
Architectural Patterns & Principles
• Single-process, single-port HTTP server
• Modular internal layering (Listener → Parser → Router → Handler → Writer)
• Separation of concerns: static vs. dynamic content
• In-memory caching to improve static file performance
• No external frameworks (zero dependencies)