The REST Api for money transfer. Technologies used:
- Maven as project management tool
- SparkJava framework for REST
- Guice for dependency injection
- JUnit and Mockito for testing
\revolut\target\site\apidocs
or
https://vighnesh.org/revolut/apidocs
To run the application:
mvn clean package
//will create jar filejava -jar revolut\target\revolut-1.0-SNAPSHOT.jar
//will run application on port 8080
This application has two impementations of services:
- When datastore is represented as Map.
- When datastore is represented as H2 (in-memory) database.
By default application starts in MAP mode (using Map as datastore). User can specify the mode when the programm is started:
- SQL mode:
java -jar revolut\target\revolut-1.0-SNAPSHOT.jar SQL
Description | Request | Path | Response | Example |
---|---|---|---|---|
Create new account with balance | POST | /account | JSON with info about account | Input: { "balance": 100 } Output: { "id": 1, "balance": 100} |
Get account by id | GET | /account/{id} | JSON with info about account | Output: { "id": 1, "balance": 100} |
Transfer money | POST | /transfer | JSON with info about transfer status | Input: { "fromId": 1, "toId": 2, "amount": 100 } Output: {Transfer Completed} |
Example CURLs
curl -i -d "{ \"balance\": 100 }" --header "Content-Type: application/json" -X POST http://localhost:8080/account
curl -i -d "{\"fromId\": 1, \"toId\": 2, \"amount\": 100}" --header "Content-Type: application/json" -X POST http://localhost:8080/transfer
curl -i --header "Content-Type: application/json" -X GET http://localhost:8080/account/2
The possible exceptions:
- In case the account doesn't exists (int get account or transfer REST calls) the "Account with id = {id} wasn't found" will be displayed;
- In case transfer is happening to the same account the "Can't transfer the money to the same account." will be displayed;
- In case the balance on the fromAccount is less than the required amout the "Account with id = {id} doesn't have enough balance to transfer this amount = {amount}" will be displayed;