Scala, Http4s, Cats-Effect
Basic Account level locking for updates using Cats-Effect Ref[IO] and Semaphore[IO]
- The following links describe the API calls. Use a Rest client such as Postman on Chrome.
Method: Post
Uri: http://127.0.0.1:8080/accounts
Header: Content-Type: application/json
{
"accHolderName":"Joey",
"balance":200
}
{
"accNumber": "1000",
"accHolderName": "Joey",
"balance": 200
}
{
"accHolderName":"JoeJoeJr",
"balance":0
}
Method: Post
Uri: http://127.0.0.1:8080/accounts/1000/transfer
Header: Content-Type: application/json
{
"destAccNum":"1001",
"transferAmount":99
}
{
"sourceAccount": {
"accNumber": "1000",
"accHolderName": "Joey",
"balance": 101
},
"destAccount": {
"accNumber": "1001",
"accHolderName": "JoeJoeJr",
"balance": 99
},
"transferAmount": 99
}
Insufficient funds in source account will have Http Status Code = 400 Bad Request
{
"sourceAccNum": "1000",
"destAccNum": "1001",
"transferAmount": 99,
"description": "Not enough funds available in account: 1000 "
}
Account Not Found for source account path param or destination destAccNum
in json body will have Http Status Code = 404 Not Found
{
"accountNumber": "1000000",
"description": "Account Number doesn't exist: 1000000"
}
Method: Post
Uri: http://127.0.0.1:8080/accounts/1000/deposit
Header: Content-Type: application/json
{
"depositAmount":10000
}
{
"account": {
"accNumber": "1001",
"accHolderName": "Junior",
"balance": 120200
},
"depositAmount": 10000
}
Account Not Found for destination account number in path param will have Http Status Code = 404 Not Found
{
"accountNumber": "1000000",
"description": "Account Number doesn't exist: 1000000"
}
Method: Get
Uri: http://127.0.0.1:8080/accounts
Header: Content-Type: application/json
[
{
"accNumber": "1001",
"accHolderName": "Junior",
"balance": 200
},
{
"accNumber": "1000",
"accHolderName": "Joey",
"balance": 200
}
]
Method: Get
Uri: http://127.0.0.1:8080/accounts/1000
Header: Content-Type: application/json
{
"accNumber": "1000",
"accHolderName": "Joey",
"balance": 200
}
Account Not Found for account number in path param will have Http Status Code = 404 Not Found
{
"accountNumber": "1000000",
"description": "Account Number doesn't exist: 1000000"
}