Design and implement a RESTful API (including data model and the backing implementation) for money transfers between accounts.
- In project directory run
gradlew clean build
on Windows or./gradlew clean build
on UN*X to compile, run tests and package the application. - Go to
build/libs
and run the application viajava -jar transfer-service.jar
. It will start server on 8080 port (if you want to change the port, you should run application viajava -Dhttp.port=other_port_number -jar transfer-service.jar
, whereother_port_number
- number of http port which you prefer).
- Javalin - A simple web framework
- H2 - Java SQL database
- Flyway - A database migration tool
- Guice - DI framework
- Lombok - An annotation-based code generator
- H2 is used as data storage. This causes a file system to become clogged with database stuff (doesn't take up much space, because when the application starts and stops, flyway is clearing the data).
- The application supports transactions only on DAO-level.
All requests to the API are relative http://localhost:port
Endpoint | Description | Parameters | Success Response/Status Code |
---|---|---|---|
POST /account/:balance |
Creates new account with specified balance | :balance - balance on account |
{ "id": id, "balance": balance } 201 CREATED |
GET /account/:id |
Returns account by id | :id - account's id |
{ "id": id, "balance": balance } 200 OK |
DELETE /account/:id |
Deletes account by id | :id - account's id |
204 NO CONTENT |
POST /account/:fromId/transfer/:toId/:amount |
Transfers specified amount of money from account to another account |
:fromId - account's id that balance will be reduced
:toId - account's id that balance will be increased
:amount - amount of money which will be transferred
|
204 NO CONTENT |
Status Code | Error |
---|---|
404 NOT FOUND | Account was not found. |
400 BAD REQUEST | The balance value must not be negative. |
400 BAD REQUEST | The transfer of money to the same account is not allowed. |
400 BAD REQUEST | Not enough money on balance. |
4**, 5** | Other unhandled errors. |