https://github.com/dhanushgr/springboot-loadsapi
Java Spring Boot (backend framework) project which demonstrates REST API methods with PostgreSQL. Exception handling with custom error message.
https://github.com/dhanushgr/springboot-loadsapi
java jpa postgresql spring spring-boot spring-mvc
Last synced: 5 months ago
JSON representation
Java Spring Boot (backend framework) project which demonstrates REST API methods with PostgreSQL. Exception handling with custom error message.
- Host: GitHub
- URL: https://github.com/dhanushgr/springboot-loadsapi
- Owner: dhanushgr
- Created: 2024-07-01T14:49:33.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-23T19:31:08.000Z (10 months ago)
- Last Synced: 2025-02-02T04:23:46.899Z (5 months ago)
- Topics: java, jpa, postgresql, spring, spring-boot, spring-mvc
- Language: Java
- Homepage:
- Size: 95.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Spring Boot REST API with PostgreSQL
This project demonstrates various REST API methods (GET, PUT, POST, DELETE) using Java's Spring Boot framework and PostgreSQL database.
Tech stack: Java Spring Boot 3, PostgreSQL database, JPA (Java Persistence API)\
Tools used: Postman, PgAdmin Postgresql database console, IDE (Intellij or VSCode or Eclipse)Please refer to the [Steps to run](#steps-to-run) section for instruction on how to clone and run this application.
### REST API Method Table
```
| Number | API Name | HTTP Method | Path | Status Code | Additional details |
|--------|-----------------------|-------------|-----------------------------|----------------|---------------------------------------|
| 1 | GET load | GET | /load | 200 OK | All load details are retrieved |
| 2 | POST load | POST | /load | 201 Created | A new load is created |
| 3 | GET load by Id | GET | /load/{id} | 200 OK | Specific load is fetched by Id |
| 4 | GET load by shipperId | GET | /load/shipperId/{shipperID} | 200 OK | Specific load is fetched by shipperId |
| 5 | PUT load | PUT | /load/{id} | 200 OK | Specific load is updated |
| 6 | DELETE load | DELETE | /load/{id} | 204 No Content | Specific load is deleted |
```### Spring Boot Architecture
|  |
|:--:|
| *Architecture of Spring Boot Framework* |### Version details:
The versions can be found in the file `pom.xml`. You can update the versions in pom.xml [here](https://github.com/dhanushgr/SpringBoot-LoadsAPI/blob/main/pom.xml).* Java version: 21
* Spring boot version: 3.3.2
* JPA version: 3.2.5
* Postgresql version: 42.7.3### Steps to run
1. Clone this git repository to your local computer
```commandline
git clone [email protected]:dhanushgr/SpringBoot-LoadsAPI.git
```
2. PostgreSQL Database setup:
* Make sure that you have "PostgreSQL pgadmin" and "Postman" installed in your system. You can search in Google for the installation steps.
* Open Pgadmin (PostgreSQL console) and create a new database called `LoadAPI` in your Pgadmin console. You can search in Google for "How to create database in postgresql pgadmin"
* Default port of PostgreSQL is `5432`. If there is a port conflict (port already in use), then you need to update the postgresql port in `spring.datasource.url` present in the file `src/main/resources/application.properties`:
https://github.com/dhanushgr/SpringBoot-LoadsAPI/blob/main/src/main/resources/application.properties#L4
3. Run the project using Maven OR your IDE:
* Using Maven: Install [Apache Maven](https://maven.apache.org/download.cgi), setup maven in the `PATH` variable and verify the command `mvn -version`. Finally, run the project:
```
cd SpringBoot-LoadsAPI/
./mvnw spring-boot:run
```
* Using IDE: Open the project `SpringBoot-LoadsAPI` using your IDE (Intellij or VSCode or Eclipse etc.) and navigate to `src/main/java/com/dhanush/springproject/SpringprojectApplication.java`. Right click on `SpringprojectApplication.java` and click on `Run`
4. Open Postman and then try out various REST API methods (GET, PUT, POST, DELETE). Alternatively, you can use `curl` command instead of Postman.
5. You can verify the data present by running `SELECT` SQL queries in PostgreSQL pgadmin console.### Example screenshots
GET request for empty database :

Empty database :

POST request to add load detail(with comment) :

posted detail in database :

POST request to add load detail(without comment) :

posted detail in database :

posted two more data in database :

GET /load : shows all the details

GET /load/{id} :

GET /load/shipperId/{shipperId} :

PUT /load/{id} :

PUT /load/{id} updated in database :

Exception handling for PUT request:

Exception handling for GET request(/load/{id}): NOT_FOUND

Exception handling for GET request(/load/shipperId/{shipperId}): INTERNAL_SERVER_ERROR

DELETE request /load/{id}:

deleted the specific load detail for given id:
