Skip to content

full-bearded-dev/spring-crud-postgres-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot CRUD Postgres Example

An example repository for creating a Spring Boot CRUD application that connects to a PostgreSQL database.

Setup and Running the Application

Install and run Postgres through Docker:

docker run --name postgres \
  -e POSTGRES_USER=dev \
  -e POSTGRES_PASSWORD=password \
  -e POSTGRES_DB=test_db \
  -p 5432:5432 \
  -d postgres

Verify Docker is running:

docker ps

Run the application:

./gradlew bootRun

Testing the Application

You can test this app using the cURL commands below. You may also prefer to use Postman for testing APIs which is more user-friendly.

Create User

curl -X POST http://localhost:8080/api/users \
  -H "Content-Type: application/json" \
  -d '{"name": "Jon","email": "jon@example.com", "age": 40}'

Get All Users

curl -X GET http://localhost:8080/api/users

Get Single User by ID

curl -X GET http://localhost:8080/api/users/1

Update User

curl -X PUT http://localhost:8080/api/users/1 \
-H "Content-Type: application/json" \
-d '{"name": "JonUpdated", "email": "jon-updated@example.com", "age": 41}'

Delete User

curl -X DELETE http://localhost:8080/api/users/1

About

An example repository for creating a Spring Boot CRUD application that connects to a PostgreSQL database.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages