This is a RESTful API for a Human Resources (HR) system, developed as part of a personal Java challenge. It is designed as a backend service to manage employee records, providing a set of endpoints for standard CRUD operations.
- Create new employee records.
- Read all employees or a single employee by their ID.
- Update existing employee information.
- Delete employee records.
- Spring Boot: The core framework for building the backend.
- Spring Data JPA: For handling data persistence to a MySQL database.
- Lombok: To reduce boilerplate code in model classes.
- MySQL: The relational database used for data storage.
- Logback: For robust and configurable application logging.
First, you need to configure your database connection in the src/main/resources/application.properties
file.
Properties
# Database Configuration
spring.datasource.url=jdbc:mysql://localhost:3306/human_resources_db?createDatabaseIfNotExist=true
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# JPA Configuration
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
# Server port
server.port=8080
Make sure to replace your_username
and your_password
with your actual MySQL credentials. The database URL includes the parameter createDatabaseIfNotExist=true
, which will create the database if it does not already exist.
Once the database is configured, you can run the application directly from your IDE by executing the HrApplication.java
main class. Alternatively, you can use Maven:
mvn spring-boot:run
The API will be accessible at http://localhost:8080/hr-app
.
- GET
/hr-app/employees
: Get a list of all employees. - POST
/hr-app/employees
: Add a new employee. - GET
/hr-app/employees/{id}
: Get a specific employee by their ID. - PUT
/hr-app/employees/{id}
: Update an existing employee by their ID. - DELETE
/hr-app/employees/{id}
: Delete an employee by their ID.