Skip to content

sebastian-c87/SpringBoot-REST-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

First REST API with Spring Boot

Project Overview

This project is a First REST API application created as part of a Java programming course at Vistula University. It is built using the Spring Boot Framework to demonstrate the implementation of a RESTful API for managing products. The application supports CRUD (Create, Read, Update, Delete) operations and integrates with Spring Data JPA and Hibernate for database interactions. Additionally, H2 Database is used for in-memory data persistence, and Swagger UI is included for API documentation and testing.

Features

The application provides the following functionalities:

  1. Create a Product (HTTP POST)
  2. Retrieve a Product by ID (HTTP GET)
  3. Retrieve All Products (HTTP GET)
  4. Update a Product (HTTP PUT)
  5. Delete a Product (HTTP DELETE)
  6. Exception Handling for invalid requests or missing resources.

Technologies Used

  • Java 21: Main programming language.
  • Spring Boot 3.1.4: Framework for developing the REST API.
  • Spring Data JPA: For seamless integration with the database.
  • Hibernate: ORM framework for database operations.
  • H2 Database: In-memory database for data storage.
  • Swagger UI: API documentation and testing.
  • Maven: Dependency and build management.

Project Structure

The project follows a layered architecture:

  • api: Contains request and response classes for managing API requests and responses.
  • domain: Represents the entity class (Product) with annotations for Hibernate.
  • repository: Interfaces for data access, including integration with JpaRepository.
  • service: Business logic for handling product operations.
  • support: Utility classes and exception handling mechanisms.
  • shared.api.response: Classes for consistent error response formatting.
  • resources: Configuration files, including application properties and Swagger setup.

Getting Started

Prerequisites

Ensure the following are installed on your system:

  1. Java 21
  2. Maven

Running the Application

  1. Clone the repository:

    git clone <repository-url>
    cd FirstRestApi
  2. Build and run the application:

    mvn spring-boot:run
  3. Access the application:

    • API base URL: http://localhost:8080
    • Swagger UI: http://localhost:8080/swagger-ui/index.html

Testing the API

The API can be tested using:

  1. Swagger UI: Navigate to the provided URL to test API endpoints interactively.
  2. Postman: Import the API endpoints and test requests manually.

Database Access

To view the H2 Database Console:

  1. Go to http://localhost:8080/console/
  2. Use the following credentials:
    • JDBC URL: jdbc:h2:mem:testdb
    • Username: sa
    • Password: (leave blank)

Exception Handling

The application includes a custom exception handling mechanism:

  • ProductNotFoundException: Thrown when a product with a specific ID is not found.
  • Global Exception Handler: Formats exceptions into a readable ErrorMessageResponse JSON structure.

Future Enhancements

  • Implement authentication and authorization.
  • Add more comprehensive logging using SLF4J.
  • Enhance data validation for product inputs.

Contributors

  • Sebastian Ciborowski - Using materials provided by lecturer Dominik Bielecki of Vistula University

License

This project is open-source and does not have any specific license, meaning it can be freely used and modified for educational or personal purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages