The Spring Boot Web API Demo is a web API project developed using Java and Spring Boot, designed to provide basic RESTful services. It's an ideal starting point for anyone who wants to quickly learn CRUD operations, API testing, and modern web service architecture.
This project uses Java Spring Boot, a widely preferred framework in enterprise applications with strong community support. The RESTful architecture is adopted, and the Model-View-Controller (MVC) design pattern is applied. DTOs (Data Transfer Objects) are used for secure and flexible data transport. UUIDs are preferred for user identifiers to ensure uniqueness and security. To enhance maintainability and safety, immutable objects and encapsulation (private/final variables) are used wherever possible. The API is tested using Postman and Swagger UI.
Before starting the project, ensure the following software is installed:
- Java JDK 17+ Download OpenJDK
- Git Download Git
- IDE: IntelliJ IDEA, Eclipse, or VS Code (Java Extension Pack)
- Maven (comes with the project as a wrapper)
- (Optional) Postman or Swagger UI for API testing
- Clone the Project:
git clone https://github.com/yourusername/Spring-Boot-WebAPI.git cd Spring-Boot-WebAPI- Download Dependencies & Build the Project:
# Linux/Mac ./mvnw clean install # Windows mvnw.cmd clean install- Run the Project:
# Linux/Mac ./mvnw spring-boot:run # Windows mvnw.cmd spring-boot:run- Configuration Files:
Basic settings are located in:
src/main/resources/application.properties Example:
spring.application.name=demo #server.port=8080You can modify the port or other settings here.
After starting the project, you can use the API as shown below:
POST http://localhost:8080/users/newuserJSON body:
{ "userName": "user_name", "userPassword": "user_password" }Response:
"User user_name created with id: b77202f8-21e5-4a32-8432-959cf8a5121a"Installing Postman:
- Download Postman
- Open the app and create a new request.
Usage:
-
Create a new collection and add your API requests.
-
For example, to create a user:
-
Method:
POST -
URL:
http://localhost:8080/users/newuser -
Go to Body → raw → JSON and enter:
{ "userName": "user_name", "userPassword": "user_password" } -
Press “Send”.
-
You can test GET, PUT, and DELETE in a similar manner.
Add this dependency to your pom.xml if Swagger is not included:
<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>1.7.0</version> </dependency>Rebuild and restart the project, then navigate to:
http://localhost:8080/swagger-ui.html Swagger UI allows you to:
- View all endpoints and descriptions
- Test endpoints directly via “Try it out”
- View request schemas and models
GET http://localhost:8080/users/{id} Example response:
{ "id": "b77202f8-21e5-4a32-8432-959cf8a5121a", "userName": "user_name" }- Quick setup with Spring Boot
- Basic RESTful endpoint examples
- Easily extendable architecture
- Ready-to-use test structure (JUnit)
- Maven-based dependency management
Spring-Boot-WebAPI/ ├── src/ │ ├── main/ │ │ ├── java/com/example/demo/ │ │ │ ├── DemoApplication.java │ │ │ ├── controller/ │ │ │ │ └── UserController.java │ │ │ ├── dto/ │ │ │ │ └── UserRequest.java │ │ │ └── model/ │ │ │ └── User.java │ │ └── resources/ │ │ └── application.properties │ └── test/ │ └── java/com/example/demo/ │ └── DemoApplicationTests.java ├── pom.xml ├── mvnw / mvnw.cmd └── ... - DemoApplication.java: Entry point of the application.
- UserController.java: Contains REST endpoints for user operations.
- UserRequest.java: DTO used to receive data from clients.
- User.java: User model class.
- application.properties: Application configuration file.
- DemoApplicationTests.java: Basic test class.
- pom.xml: Maven dependency and build configuration.
- Adding a New Endpoint: Create a new controller under
controller/. - Database Integration: Add DB settings inside
application.properties. - Adding New Dependencies: Modify
pom.xmland run./mvnw clean install.
- JAVA_HOME Error: Ensure JDK is properly installed and environment variables are set.
- Port Conflict: Change the server port in
application.properties. - Dependency Issues: Run
./mvnw clean installfor a clean build.
During development, multiple languages and frameworks (ASP.NET, PHP, Python Flask, and Spring Boot) were evaluated. Spring Boot was selected due to:
- Strong enterprise usage
- Large, active community
- Robust REST support
- Advanced configuration and security features
The REST architecture ensures scalability and flexibility. MVC design pattern improves readability and maintainability. DTOs are used to expose only necessary fields and maintain data encapsulation.
User IDs are generated using UUID for security and uniqueness. Model fields are defined as private and final to encourage immutability and safer object design.
The API was tested using Postman and Swagger UI.
