A lightweight, custom HTTP server built in Java using com.sun.net.httpserver.
This project demonstrates a robust server with features like routing, static file serving, JSON handling, and concurrent request processing.
- Multiple Endpoints:
/: Serves a welcome HTML page./api/greet?name=<name>: Returns a JSON greeting (GET)./api/data: Accepts JSON data (POST) and echoes it back./static/*: Serves static files (e.g., HTML, CSS) from thestaticdirectory.
- Configuration: Loads port and static directory from
server.properties. - Concurrency: Uses a thread pool to handle multiple requests efficiently.
- Logging: Logs requests and errors to
server.log. - Error Handling: Returns appropriate HTTP status codes (e.g., 404, 405).
- Query Parsing: Supports URL query parameters.
- JSON Support: Handles JSON responses and POST request bodies.
Edit server.properties to change:
port: Server port (default: 9000).static.dir: Directory for static files (default:static_content).
Logs are written to server.log with timestamps, request details, and errors.
- Add authentication middleware.
- Support HTTPS with SSL/TLS.
- Implement RESTful CRUD operations.
- Add unit tests with JUnit.
This server demonstrates core backend development skills, including HTTP protocol handling, concurrency, configuration management, and logging; Tryout virtual threads and new java features.