Skip to content

REST Api Java11/Jetty/Jersey/H2 + API integration tests

Notifications You must be signed in to change notification settings

majonga88/the-bank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

THE BANK

A standalone and lightweight Rest API powered by Jetty Server

The goal is to provide a apis allowing to provide money transfer / withdraw / deposit

Table of Contents

Project Structure

.
├── account (rest api)
├── user (rest api)
└── data.sql (data of application)

Out of the box, we've got :

  • JDK 11
  • Jetty server / Jersey
  • Database : H2
  • Testing :
    • Dao test with H2/junit
    • Api test with jersey test framework/junit

How to

Run

Need Java 11 to launch

    mvn clean install
    java -jar the-bank-1.0.0-SNAPSHOT.jar YourPath/data.sql  

CURL

User part

Creation

Create a user

curl -X POST \
  http://localhost:8080/api/users \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
	"username": "dgreenwich",
	"firstName": "Daniel",
	"lastName": "Greenwich",
	"email": "d.greenwich@mail.com"
}'

Verify the user created

curl -X GET \
  http://localhost:8080/api/users/dgreenwich \
  -H 'cache-control: no-cache'

Waiting result

{
    "id": 4,
    "username": "dgreenwich",
    "firstName": "Daniel",
    "lastName": "Greenwich",
    "email": "d.greenwich@mail.com"
}

Account part

Creation

Create an account for the created user

curl -X POST \
  http://localhost:8080/api/accounts \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
	"username":"dgreenwich",
	"name":"Bank Account",
	"balance":"100",
	"currency":"EUR"
}'

Verify the account created

curl -X GET \
  http://localhost:8080/api/accounts/6 \
  -H 'cache-control: no-cache'

Waiting result

{
    "id": 6,
    "username": "dgreenwich",
    "name": "Bank Account",
    "balance": 100,
    "currency": "EUR"
}
Deposit

Make a deposit on his created account

curl -X PUT \
  http://localhost:8080/api/accounts/6/deposit/100 \
  -H 'cache-control: no-cache'

Verify the deposit on account

curl -X GET \
  http://localhost:8080/api/accounts/6 \
  -H 'cache-control: no-cache'

Waiting result

{
    "id": 6,
    "username": "dgreenwich",
    "name": "Bank Account",
    "balance": 200,
    "currency": "EUR"
}
Transfer

And make a money transfer to an existing account

curl -X POST \
  http://localhost:8080/api/accounts/transfer \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
	"to": "6",
	"from": "3",
	"amount": "100",
	"currency": "EUR"
}'

Verify the debited account

curl -X GET \
  http://localhost:8080/api/accounts/3 \
  -H 'cache-control: no-cache'

Waiting result

{
    "id": 3,
    "username": "jdeer",
    "name": "Bank Account",
    "balance": 200,
    "currency": "EUR"
}

Verify the credited account

curl -X GET \
  http://localhost:8080/api/accounts/6 \
  -H 'cache-control: no-cache'

Waiting result

{
    "id": 6,
    "username": "dgreenwich",
    "name": "Bank Account",
    "balance": 100,
    "currency": "EUR"
}

About

REST Api Java11/Jetty/Jersey/H2 + API integration tests

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages