This is a Spring Boot project that implements basic CRUD(Create, Read, Update, Delete) operations for managing employee data via RESTful APIs. It serves as a foundational project to understand how Spring Boot works with REST endpoints and an MySQL database.
📌 Features
- Create a new employee
- Retrieve all employees
- Retrieve an employee by ID
- Update employee details
- Delete an employee
- RESTful API architecture
- MySQL Database
Well-structured with best practices using Spring Boot annotations
🧱 Technologies Used
- Java 17+
- Spring Boot
- Spring Data JPA
- MySQL
- Maven
- JUnit and Mockito
- Docker
Backend Setup
- Clone the repositor:
- Update the database configuration in
application.properties
- Build the project:
- Run the application:
Flow of the Program
-
Initally there is no table in database 'employee_directory' called 'employee'.
-
After running the Spring Boot Application, 'employee' table is created.
3.Initially, the table is blank.
-
Hitting the GET
http://localhost:8080/api/employees
API using Postman.blank JSON response.
-
Hitting the POST
/api/employees
API using Postman with JSON data. { "firstName": "Alice", "lastName": "Walker", "email": "[email protected]" } -
Checking the data in MySQL Workbench.
1 employee created. Why first_name and last_name columns are blank? OOPS! the column names are different in Employee POJO class, than the JSON data we provided.
-
Lets create another employee the same way.
2nd employee created. Let's check in the database.
Now it is good.
-
Lets Delete employee record 4. Before deleting ->
Postman Screenshot ->
After deleting ->
API Endpoints
- Create Employee
- POST
/api/employees
{ "firstName": "Jane", "lastName": "Smith", "email": "[email protected]" }
- Get All Employees
- GET
/api/employees
- Get Employee by ID
- GET
/api/employees/1
- Update Employee
- PUT
/api/employees
{ "id": 1, "firstName": "Jane Updated", "lastName": "Smith", "email": "[email protected]" }
- Delete Employee
- DELETE
/api/employees/4