Skip to content

Seymagocmez/Spring-Boot-WebAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Web API - User Controller

Project Description

webapi_thumb

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.

Requirements

Before starting the project, ensure the following software is installed:

Installation Steps

  1. Clone the Project:
git clone https://github.com/yourusername/Spring-Boot-WebAPI.git cd Spring-Boot-WebAPI
  1. Download Dependencies & Build the Project:
# Linux/Mac ./mvnw clean install # Windows mvnw.cmd clean install
  1. Run the Project:
# Linux/Mac ./mvnw spring-boot:run # Windows mvnw.cmd spring-boot:run
  1. Configuration Files:

Basic settings are located in:

src/main/resources/application.properties 

Example:

spring.application.name=demo #server.port=8080

You can modify the port or other settings here.

Usage Guide

After starting the project, you can use the API as shown below:

Example API Call

POST http://localhost:8080/users/newuser

JSON body:

{ "userName": "user_name", "userPassword": "user_password" }

Response:

"User user_name created with id: b77202f8-21e5-4a32-8432-959cf8a5121a"

Testing with Postman

Installing Postman:

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.

Swagger UI Setup (Optional)

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

Example GET Request

GET http://localhost:8080/users/{id} 

Example response:

{ "id": "b77202f8-21e5-4a32-8432-959cf8a5121a", "userName": "user_name" }

Features

  • Quick setup with Spring Boot
  • Basic RESTful endpoint examples
  • Easily extendable architecture
  • Ready-to-use test structure (JUnit)
  • Maven-based dependency management

Project Structure

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.

Customization

  • Adding a New Endpoint: Create a new controller under controller/.
  • Database Integration: Add DB settings inside application.properties.
  • Adding New Dependencies: Modify pom.xml and run ./mvnw clean install.

Troubleshooting

  • 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 install for a clean build.

Project Development Summary

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.


About

Java Spring Boot üzerinde geliştirilmiş, temel RESTful servisleri sunan bir web API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages