This project demonstrates how to create a simple REST API using Spring Boot, PostgreSQL, and JPA. The API allows for basic CRUD (Create, Read, Update, Delete) operations on a product entity.
- Java: 21
- Spring Boot: Latest version
- PostgreSQL: Database
- Maven: Project management and build tool
- Eclipse: IDE for Java development
-
Clone the Repository:
git clone https://github.com/yourusername/springapi.git cd springapi
-
Create PostgreSQL Database:
Open your PostgreSQL client and create a new database.
CREATE DATABASE springapidb;
-
Configure Application Properties:
Update the src/main/resources/application.properties file with your PostgreSQL database credentials.
spring.datasource.url=jdbc:postgresql://localhost:5432/springapidb spring.datasource.username=your_postgresql_username spring.datasource.password=your_postgresql_password spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true
-
Build the Project:
Make sure you have Maven installed. Run the following command in your project directory.
mvn clean install
-
Run the Application:
You can run the application from your IDE (Eclipse) or use the command line.
mvn spring-boot:run
Once the application is running, you can interact with the API using a tool like Postman or Curl.
Create a Product (POST):
URL: http://localhost:8080/api/v1/products
Request Body (JSON):
{
"name": "Product 1",
"price": 100.0,
"quantity": 10
}
Get All Products (GET):
URL: http://localhost:8080/api/v1/products
Get a Product by ID (GET):
URL: http://localhost:8080/api/v1/products/{id}
Delete a Product (DELETE):
URL: http://localhost:8080/api/v1/products/{id}
This project is licensed under the MIT License - see the LICENSE file for details.