In this project, we're set up a simple Rails API-only-application. Rails API-only-applications are slimmed down compared to traditional Rails web applications.
- Ruby v2.7.2
- Ruby on Rails v7.0.0.alpha2
- RSpec-Rails for testing
The API will expose the following RESTful endpoints.
| Endpoint | Functionality |
|---|---|
| GET /api/v1/users/:id/balance | Check wallet balance |
| POST /api/v1/users/:id/deposit | Deposit money into wallet |
| POST /api/v1/users/:id/transfer | Transfer money to another user |
| POST /api/v1/users/:id/withdraw | Withdraw money from wallet |
To get a local copy up and running follow these simple example steps.
Ruby: 2.7.2 Rails: 7.0.0.alpha2 Postgres: 14.0
# unzip crypallet.zip
$ cd crypalletInstall gems with:
$ bundle installSetup database with:
make sure you have postgress sql installed and running on your system
$ rails db:create
$ rails db:migrate
$ rails db:seedhttps://dbdiagram.io/d/6183064ed5d522682df795f8
Start server with:
$ rails serverOpen Insomnia or Postman API request tool.
- Path: /api/v1/users/1/balance
- Method: GET
- Headers:
- Accept: application/json
- Content-Type: application/json
- Response:
- Status: 200
- Body:
- { "balance": 9500 }
- Errors:
- [404] :not_found
- [422] :unprocessable_entity
- Path: /api/v1/users/1/deposit
- Method: POST
- Headers:
- Accept: application/json
- Content-Type: application/json
- Request body:
- { "amount": 1000 }
- Response:
- Status: 200
- Body:
- { "balance": 9500 }
- Errors:
- [404] :not_found
- [422] :unprocessable_entity
- Path: /api/v1/users/1/transfer
- Method: POST
- Headers:
- Accept: application/json
- Content-Type: application/json
- Request body:
- { "amount": 500, "to_user_id": 2 }
- Response:
- Status: 200
- Body:
- { "balance": 9000 }
- Errors:
- [404] :not_found
- [422] :unprocessable_entity
- Path: /api/v1/users/1/withdraw
- Method: POST
- Headers:
- Accept: application/json
- Content-Type: application/json
- Request body:
- { "amount": 500 }
- Response:
- Status: 200
- Body:
- { "balance": 9000 }
- Errors:
- [404] :not_found
- [422] :unprocessable_entity
$ rpsecThe core of the project is the User controller. The User controller is responsible for the balance and deposit and withdraw and transfer action.
- Need to add token verify for each api call.
- Loading test with large traffic.
- Pessimistic locking may cause performance issue.