Skip to content

john-ngai/spring-web-postgres-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tutorial: Spring Web and PostgreSQL

References

Environment Requirements

  • Podman Desktop

Getting Started

PostgreSQL Database

  1. Open the Podman Desktop application.

  2. Download the latest postgres image:

podman pull postgres
  1. Create and run the postgres container:
podman run --name postgres-db -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres
  1. Connect to the postgres server:
podman exec -it postgres-db psql -U postgres
  1. Create the new database:
CREATE DATABASE springwebdb OWNER postgres;
  1. Connect to the database:
\c springwebdb

Spring Boot Web Service

  1. From another terminal, start the web service using:
mvn spring-boot:run
  1. Test the connection by sending a GET request using curl:
curl -s localhost:8080/employees
  1. Create an employee by sending a POST request:
curl -s -X POST localhost:8080/employees \
  -H "Content-Type: application/json" \
  -d '{"firstName": "foo", "lastName": "bar", "dateOfBirth": "2023-05-04"}'
  1. Verify using curl:
curl -s localhost:8080/employees
  1. Switch to the postgres terminal and verify again using psql:
SELECT * FROM employees;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages