This repository provides a RESTful CRUD API implementation using Spring Boot. It includes three different approaches for managing entities: EmployeeController
, ProductController
, and CompanyController
.
Ensure you have the following installed:
- Java Development Kit (JDK) 8 or higher
- Apache Maven
- MySQL
Add the following dependencies in your pom.xml
file:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
</dependencies>
- Create a MySQL database.
- Update the application.properties file with your database configuration:
spring.datasource.url=jdbc:mysql://localhost:3306/your_database_name
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update
#
# Spring data Rest properties
#
spring.data.rest.base-path=/base/api
mvn spring-boot:run
Class Diagram:
-
Insert New Employee
- POST
http://localhost:8080/api/employees
- Request Body:
{ "id": 1, "firstName": "Leslie", "lastName": "Andrews", "age": 10, "gender": "Male", "role": "Software Engineer 1" }
- POST
-
Get All Employees
- GET
http://localhost:8080/api/allemployees
- GET
-
Get Employee by ID
- GET
http://localhost:8080/api/employees/{id}
- GET
-
Update Existing Employee
- PUT
http://localhost:8080/api/employees
- Request Body:
{ "id": 1, "firstName": "Leslie", "lastName": "Andrews", "age": 10, "gender": "Male", "role": "Software Engineer 1" }
- PUT
-
Delete Existing Employee
- DELETE
http://localhost:8080/api/employees/{id}
- DELETE
Class Diagram:
-
Insert New Product
- POST
http://localhost:8080/api/products
- Request Body:
{ "productId": 4, "productName": "sharpner", "productPrice": 5.0, "productStatus": "IN_STOCK" }
- POST
-
Get All Products
- GET
http://localhost:8080/api/allProducts
- GET
-
Get Product by ID
- GET
http://localhost:8080/api/products/{id}
- GET
-
Update Existing Product
- PUT
http://localhost:8080/api/products
- Request Body:
{ "productId": 4, "productName": "sharpner", "productPrice": 5.0, "productStatus": "IN_STOCK" }
- PUT
-
Delete Existing Product
- DELETE
http://localhost:8080/api/products/{id}
- DELETE
-
Get Products by Name
- GET
http://localhost:8080/api/products?productName={productName}
- GET
Class Diagram:
-
Insert New Company
- POST
http://localhost:8080/base/api/companies
- Request Body:
{ "companyId": 3, "companyName": "amazon" }
- Request Body:
- POST
-
Get All Companies
- GET
http://localhost:8080/base/api/companies
- GET
-
Get Company by ID
- GET
http://localhost:8080/base/api/companies/{id}
- GET
-
Update Existing Product
- PUT
http://localhost:8080/base/api/companies/{id}
- Request Body:
{ "companyName": "zotec partners" }
- PUT
-
Delete Existing Product
- DELETE
http://localhost:8080/base/api/companies/{id}
- DELETE