A basic and small REST API made with Elixir and Phoenix for accounts
To start your Phoenix server:
- Install dependencies with
mix deps.get
- Create and migrate your database with
mix ecto.setup
- Start Phoenix endpoint with
mix phx.server
or inside IEx withiex -S mix phx.server
Great! Now you can visit localhost:4000
from your browser.
This endpoint will give the balance from requested account
Endpoint to reset the accounts database
Endpoint to deposit, withdraw or transfer amount between accounts
Mandatory fields:
{
"type": "deposit",
"destination": "<account_id>",
"amount": 0
}
Mandatory fields:
{
"type": "withdraw",
"origin": "<account_id>",
"amount": 0
}
Mandatory fields:
{
"type": "transfer",
"origin": "<account_id>",
"destination": "<account_id>",
"amount": 0
}
- When the deposit is made to a non-existing account, the account will be created with a
balance
equal to the depositedamount
. - When deposit is made to existing account,
amount
is added to the account balance
- When a withdraw is made from a non-existing account, the return is 404 http code with
"0"
text - When withdraw is made from a existing account,
amount
is subtracted from the accountbalance
- When a transfer is made from a non-existing account to an existing account, the return is 404 http code with
"0"
text - When transfer is made from a existing account to an existing account,
amount
is subtracted from the origin accountbalance
and theamount
is added to destination accountbalance