Skip to content

movb/money-transfer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Money transfer

Simple money transfer rest service.

Notes:

Trying to stick to the principle of "the simpler the better", I did not use different database implementations, but made a simple storage based on ConcurrentHashMap. The design is also simple, but have some extensibility - versioning APIs. I also believe that transfer API must supports idempotency for safely retrying requests without accidentally performing the same operation twice, so I added optional idempotencyKey field to transaction request.

Used sparkjava for implementing REST service, gson for working with JSON, lombok for slightly easier setters and getters, Commons Cli for command line argument passing, Jersey and JUnit for unit and functional testing.

Build:

mvn clean package

Run:

  • Run the app, default port 8080:
java -jar target/money-transfer-1.0-SNAPSHOT.jar
  • Run the app, specify the port:
java -jar target/money-transfer-1.0-SNAPSHOT.jar -p 6666
  • Run Test Cases:
mvn test

API

Available methods

HTTP METHOD PATH USAGE
POST /api/v1/accounts create a new account
GET /api/v1/accounts/{accountId} get account by Id
GET /api/v1/accounts/ get all acounts information
POST /api/transfer perform transaction between 2 accounts

Methods description

Create account:

Request:
POST /api/v1/accounts
{  
   "id":"someid",
   "balance":100
} 
  • id (required)- some unique string with account id.
  • balance - a positive integer in cents representing start balance on account, default 0.
Response:
Header:
"Location":"http://localhost:8080/api/v1/account/someid"
{
  "status": "ok",
  "message": {}
}

Get account:

Request:
GET /api/v1/accounts/someid
Response:
{  
   "id":"someid",
   "balance":100
} 

Get all accounts:

Request:
GET /api/v1/accounts
Response:
[
    {  
       "id":"someid1",
       "balance":100
    },
    {  
       "id":"someid2",
       "balance":1000
    }
]

Transaction:

Request:
{  
   "from":"some-id",
   "to":"someid",
   "amount":100,
   "idempotencyKey":"some-key"
}
Response:
{
  "status": "ok",
  "message": {}
}
  • from (required) - id to charge.
  • to (required) - id to transfer moeny.
  • amount (required) - a positive integer in cents representing amount to transfer.
  • idempotencyKey - transfer API supports idempotency for safely retrying requests without accidentally performing the same operation twice.

About

Simple money-transfer API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages