Skip to content

alanjphillips/AccountServiceTaglessFinal

Repository files navigation

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.

Create Account

Perform Money Transfer

Perform Deposit

Get all Accounts

Get single Account


Create an account to be source of the money transfer:


Method: Post
Uri:    http://127.0.0.1:8080/accounts
Header: Content-Type: application/json

Body:

{
  "accHolderName":"Joey",
  "balance":200
}

Response: Note the account number in the successful response with Http Status Code = 200 OK:

{
  "accNumber": "1000",
  "accHolderName": "Joey",
  "balance": 200
}

Create another account to be destination of the money transfer:


Body:

{
  "accHolderName":"JoeJoeJr",
  "balance":0
}

Perform transfer from source account number as path param with value 1000 representing Joey:


Method: Post
Uri:    http://127.0.0.1:8080/accounts/1000/transfer
Header: Content-Type: application/json

Body:

{
  "destAccNum":"1001",
  "transferAmount":99
}

Response: Successful transfer will have Http Status Code = 200 OK

{
  "sourceAccount": {
    "accNumber": "1000",
    "accHolderName": "Joey",
    "balance": 101
  },
  "destAccount": {
    "accNumber": "1001",
    "accHolderName": "JoeJoeJr",
    "balance": 99
  },
  "transferAmount": 99
}

Errors:

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"
}

Perform deposit to account as path param with value 1000 representing Joey:


Method: Post
Uri:    http://127.0.0.1:8080/accounts/1000/deposit
Header: Content-Type: application/json

Body:

{
"depositAmount":10000
}

Response: Successful transfer will have Http Status Code = 200 OK

{
  "account": {
    "accNumber": "1001",
    "accHolderName": "Junior",
    "balance": 120200
  },
  "depositAmount": 10000
}

Errors:

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"
}

Get all accounts:


Method: Get
Uri:    http://127.0.0.1:8080/accounts
Header: Content-Type: application/json

Response:

[
  {
    "accNumber": "1001",
    "accHolderName": "Junior",
    "balance": 200
  },
  {
    "accNumber": "1000",
    "accHolderName": "Joey",
    "balance": 200
  }
]

Get an account


Method: Get
Uri:    http://127.0.0.1:8080/accounts/1000
Header: Content-Type: application/json

Response:

{
  "accNumber": "1000",
  "accHolderName": "Joey",
  "balance": 200
}

Errors:

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"
}

About

Http4s Web Server with Scala, Cats-Effect, Circe

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages