This is a simple CRUD (Create, Read, Update, Delete) application built using Spring Boot and H2 database. The application manages a list of items, allowing basic operations via a RESTful API.
- Create new items
- Retrieve all items
- Retrieve a single item by ID
- Update an existing item
- Delete an item by ID
- In-memory H2 database for easy setup and testing
- Java
- Spring Boot
- Spring Data JPA
- H2 Database
- Maven
- Java 11 or higher
- Maven
-
Clone the repository:
git clone https://github.com/yourusername/crud-example.git cd crud-example
-
Build and run the application:
./mvnw spring-boot:run
-
Access the H2 database console:
- URL:
http://localhost:8009/h2-console
- JDBC URL:
jdbc:h2:mem:testdb
- Username:
sa
- Password: (leave it empty)
- URL:
-
Create a new item
- URL:
POST /api/items
- Request Body:
{ "name": "Item Name", "description": "Item Description" }
- Response:
{ "id": 1, "name": "Item Name", "description": "Item Description" }
- URL:
-
Retrieve all items
- URL:
GET /api/items
- Response:
[ { "id": 1, "name": "Item Name", "description": "Item Description" } ]
- URL:
-
Retrieve a single item by ID
- URL:
GET /api/items/{id}
- Response:
{ "id": 1, "name": "Item Name", "description": "Item Description" }
- URL:
-
Update an existing item
- URL:
PUT /api/items/{id}
- Request Body:
{ "name": "Updated Item Name", "description": "Updated Item Description" }
- Response:
{ "id": 1, "name": "Updated Item Name", "description": "Updated Item Description" }
- URL:
-
Delete an item by ID
- URL:
DELETE /api/items/{id}
- Response:
204 No Content
- URL: