This is a basic web server project originally built with native Java, now refactored into a professional RESTful JSON API. It demonstrates fundamental backend concepts such as handling HTTP methods, thread pools for concurrency, routing, and processing JSON payloads. The goal of this project is to serve as an educational reference for building a modern web service in Java from scratch.
- REST API (JSON): Fully responds and consumes
application/jsonusing Google's Gson library. - Concurrency: Built-in
ThreadPoolExecutorfor handling multiple HTTP requests simultaneously. - Maven Architecture: Standardized project structure and dependency management.
- Dev Tooling: Code automatically formatted via Spotless (Google Java Format) and linted via Checkstyle.
- CI/CD Ready: Includes GitHub Actions for PR checks (Format/Lint/Test) and multi-stage manual deployment pipelines using SCP/SSH.
Ensure you have Java Development Kit (JDK) 17+ and Apache Maven installed on your machine.
- Clone the repository:
git clone https://github.com/FarrelAD/Basic-Web-Server-Java.git
- Navigate into the project directory:
cd Basic-Web-Server-Java
Using Maven, you can compile and start the server immediately:
mvn clean compile exec:java -Dexec.mainClass="com.server.Main"The server will be running at http://localhost:8000
If you want to build a deployment-ready Fat JAR:
mvn clean package -DskipTests
java -jar target/basic-web-server-1.0-SNAPSHOT.jarRun the automated tests:
mvn testFormat the codebase and check for linting errors:
mvn spotless:apply checkstyle:checkThis project strictly enforces code quality using Git pre-commit hooks (Spotless and Checkstyle). After cloning the repository, you must configure Git to use the local hooks directory:
git config core.hooksPath .githooksEvery time you commit, it will automatically verify formatting and linting. If it fails, the commit will be aborted.
Here are the key REST endpoints you can interact with. All endpoints strictly consume and return application/json.
GET /- Response (200 OK):
{ "status": "UP", "message": "Welcome to Basic Web Server API", "totalUsers": 8 }
- Response (200 OK):
GET /users- Response (200 OK):
[ { "name": "Alex", "job": "Data Analyst" }, { "name": "Budi", "job": "Frontend Web Developer" } ]
- Response (200 OK):
GET /users/:id(e.g./users/1)- Response (200 OK):
{ "name": "Alex", "job": "Data Analyst" }
- Response (200 OK):
POST /users- Request Body:
{ "name": "John Doe", "job": "Backend Engineer" } - Response (201 Created):
{ "status": "success", "message": "User added successfully" }
- Request Body:
PATCH /users/:id(e.g./users/1)- Request Body:
{ "job": "Senior Data Analyst" } - Response (200 OK):
{ "status": "success", "message": "Data updated successfully" }
- Request Body:
DELETE /users/:id(e.g./users/1)- Response (200 OK):
{ "status": "success", "message": "Data deleted successfully" }
- Response (200 OK):
GET /search?name=&job=(e.g./search?job=Data Analyst)- Response (200 OK):
[ { "name": "Alex", "job": "Data Analyst" }, { "name": "Dono", "job": "Data Analyst" } ]
- Response (200 OK):
The project uses the standard Maven structure:
/root
├───.github/workflows # CI/CD Pipelines
├───pom.xml # Build config and dependencies
└───src
├───main/java/com/server
│ ├─── /controller # HTTP route handlers
│ ├─── /model # Data structures and tracking
│ ├─── /utils # Parsers and HTTP helpers
│ └─── Main.java # Server initialization and Thread Pool
└───test/java/com/server
└─── /model # JUnit 5 test casesThis project is licensed under the MIT License.
This project is intended to help others learn the basics of building a robust REST API with Java ☕.
