Skip to content

This is a simple demo of how to create a REST API using Spring Boot, PostgreSQL, and JPA

License

Notifications You must be signed in to change notification settings

jevin31/spring-boot-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot REST API with PostgreSQL

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.

Table of Contents

Technologies Used

  • Java: 21
  • Spring Boot: Latest version
  • PostgreSQL: Database
  • Maven: Project management and build tool
  • Eclipse: IDE for Java development

Installation

  1. Clone the Repository:

    git clone https://github.com/yourusername/springapi.git
    cd springapi
  2. Create PostgreSQL Database:

    Open your PostgreSQL client and create a new database.

    CREATE DATABASE springapidb;
    
  3. 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
  4. Build the Project:

    Make sure you have Maven installed. Run the following command in your project directory.

    mvn clean install
    
  5. Run the Application:

    You can run the application from your IDE (Eclipse) or use the command line.

    mvn spring-boot:run
    

Usage

Once the application is running, you can interact with the API using a tool like Postman or Curl.

API Endpoints

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}

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

This is a simple demo of how to create a REST API using Spring Boot, PostgreSQL, and JPA

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages