A simple RESTful API built with Spring Boot to manage products. This application supports basic CRUD operations (Create, Read, Update, Delete) on a Product entity.
- Create a new product
- Get all products
- Get a product by ID
- Update an existing product
- Delete a product
- Java 17+
- Spring Boot
- Spring Web
- Spring Data JPA
- MySQL
- Maven
src/
├── main/
│ ├── java/
│ │ └── com.learnSpring.RestAPI/
│ │ ├── Controller/
│ │ │ └── ProductController.java
│ │ ├── Entity/
│ │ │ └── Product.java
│ │ ├── Service/
│ │ │ └── ProductService.java
│ │ └── RestApiApplication.java
│ └── resources/
│ ├── application.properties
Make sure you have the following installed:
- Java 17+
- Maven
- MySQL Server
- MySQL Workbench (for managing your database easily)
💡 MySQL Workbench is a GUI tool to interact with your database. Use it to create the database schema and inspect tables.
Use MySQL Workbench or MySQL CLI to create a database for the application:
CREATE DATABASE product_db;In src/main/resources/application.properties, update the MySQL connection:
spring.datasource.url=jdbc:mysql://localhost:3306/product_db
spring.datasource.username=root
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8DialectReplace
your_passwordwith your actual MySQL root password.
git clone https://github.com/your-username/springboot-rest-api.git
cd springboot-rest-apimvn clean installmvn spring-boot:runThe server will start at:
👉 http://localhost:8080
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/product |
Create a product |
| GET | /api/v1/products |
Get all products |
| GET | /api/v1/products/{id} |
Get product by ID |
| PUT | /api/v1/products/{id} |
Update product |
| DELETE | /api/v1/products/{id} |
Delete product |
{
"name": "Example Product",
"price": 99.99,
"quantity" : 100
}- You can use Postman or curl to test the API endpoints.
- Ensure MySQL Server is running before starting the application.
- MySQL Workbench is optional but highly recommended for visual database management.