This project demonstrates building a RESTful API using Spring Boot with features like exception handling, response handling, and unit testing. It includes integration with a MySQL database using Spring Data JPA, and utilizes technologies such as Mockito, AssertJ, JUnit 5, and H2 database for testing purposes.
- Java
- Spring Boot
- Mockito
- AssertJ
- MySQL Database
- JUnit 5
- H2 Database
- Exception Handling
- Response Handling
- Spring Data JPA
The project is structured as follows:
- Main Application Class:
RestApiApplication.java
- Controller: Contains endpoints for handling HTTP requests (
EmployeeController.java
) - Service Layer: Contains business logic (
EmployeeService.java
,EmployeeServiceImpl.java
) - Repository Layer: Provides access to the database using Spring Data JPA (
EmployeeRepository.java
) - Model: Contains data models (
Employee.java
) - Exception Handling: Custom exceptions and exception handler (
EmployeeNotFoundException.java
,NoEmployeesFoundException.java
,EmployeeExceptionHandler.java
) - Response Handling: Response handler for consistent API responses (
ResponseHandler.java
) - Unit Tests: Test cases for controllers, services, and exception handling using Mockito, AssertJ, and JUnit 5
- Clone the repository.
- Configure the MySQL database connection in
application.yaml
. - Run the application using Maven or an IDE.
- Use tools like Postman or cURL to make API requests.
- Unit tests can be run using the Maven command:
mvn test
.
Contributions to this repository are welcome! If you have any examples, tutorials, improvements, or additional features related to REST API development, we'd love to see them. Whether it's enhancing error handling, optimizing performance, adding new endpoints, or anything else that can benefit the project, feel free to submit a pull request.
- Before contributing, please ensure that your code follows the existing coding style and conventions.
- If you're adding new functionality, consider including relevant unit tests to maintain code quality.
- Provide clear and concise documentation for any changes or new features you introduce.
- Be respectful and considerate of other contributors. We value collaboration and open communication.
- Fork the repository to your own GitHub account.
- Clone the forked repository to your local machine.
- Create a new branch for your changes:
git checkout -b feature/new-feature
. - Implement your changes and ensure they pass all tests.
- Commit your changes with descriptive commit messages:
git commit -am 'Add new feature: Feature Description'
. - Push your changes to your fork:
git push origin feature/new-feature
. - Submit a pull request to the main repository.
Your contributions can help improve this project and make it more valuable to the community. Thank you for your interest and support!