naren-jha / DemoApp

Spring boot CRUD demo app with PostgreSQL and MySQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DemoApp

Database configs

PostgreSQL config

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/student
    username:
    password:
  jpa:
    hibernate:
      ddl-auto: 'create-drop'
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
        format_sql: true

MySql config

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/student
    username: root
    password: root1234
  jpa:
    hibernate:
      ddl-auto: 'create-drop'
    show-sql: true

Also, replace postgresql dependency with mysql dependency when changing the database

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
</dependency>

Curl

Create:

curl --location --request POST 'localhost:8080/api/v1/student/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "Joe Goldberg",
    "email": "joeg@gmail.com",
    "age": 25,
    "dob": "2001-06-20"
}'

Get:

curl --location --request GET 'localhost:8080/api/v1/student/'
curl --location --request GET 'localhost:8080/api/v1/student/1'

Update:

curl --location --request PUT 'localhost:8080/api/v1/student/2?name=Joe&email=joeg2@gmail.com' \
--header 'Content-Type: application/json' \
--data-raw ''

Delete:

curl --location --request DELETE 'localhost:8080/api/v1/student/1' \
--data-raw ''

Run multiple instances of the app

cd target

java -jar demo-0.0.1-SNAPSHOT.jar on default port 8080

java -jar demo-0.0.1-SNAPSHOT.jar --server.port=8081

java -jar demo-0.0.1-SNAPSHOT.jar --server.port=8082

Using RestTemplate

Synchronous client to perform HTTP requests, exposing a simple, template method API over underlying HTTP client libraries such as the JDK HttpURLConnection, Apache HttpComponents, and others.

Using WebClient

Non-blocking, reactive client to perform HTTP requests, exposing a fluent, reactive API over underlying HTTP client libraries such as Reactor Netty.

RestTemplate vs WebClient

About

Spring boot CRUD demo app with PostgreSQL and MySQL


Languages

Language:Java 100.0%