Simple money transfer rest service.
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.
mvn clean package
- 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
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 |
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.
Header:
"Location":"http://localhost:8080/api/v1/account/someid"
{
"status": "ok",
"message": {}
}
GET /api/v1/accounts/someid
{
"id":"someid",
"balance":100
}
GET /api/v1/accounts
[
{
"id":"someid1",
"balance":100
},
{
"id":"someid2",
"balance":1000
}
]
{
"from":"some-id",
"to":"someid",
"amount":100,
"idempotencyKey":"some-key"
}
{
"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.