Skip to content

Simple Banking API implementation with Elixir and Phoenix

Notifications You must be signed in to change notification settings

davidbrusius/bank

Repository files navigation

Build Status SourceLevel

Bank

Simple banking API implementend using Elixir and Phoenix.

Contributing

Dependencies:

  • Elixir 1.9.1
  • Erlang 22.0.7
  • Postgres 11

Setup the application:

  • Clone this repo git clone [email protected]:davidbrusius/bank.git
  • Access the repo directory cd bank
  • Install dependencies with mix deps.get
  • Create, migrate and add seed data to your database with mix ecto.setup

To start your Phoenix server run mix phx.server.

Now you can start sending requests to the API on http://localhost:4000.

You can use the users and accounts created by the seeds file (priv/repo/seeds.exs) to start making some requests to the API. Alternatively, you can also create your own users and accounts using the commands available in the seeds file.

API Endpoints

🔐 Authentication

Requests to authenticated endpoints are authorized through a Bearer token that should be provided in the Authorization HTTP header. Check the /api/auth/token endpoint for further details on how to generate Bearer tokens.

POST /api/auth/token

Authenticates the user using email and password credentials and generates an auth token which can be used in subsequent calls to authenticated API endpoints.

Parameters

Name Required Type Description
email required string A user email
password required string A user password

Response

Status: 201 Created

Body:

{
  "token":  "auth-token"
}

GET /api/accounts/:number

🔐 Authenticated

Return informations about the account such as its balance and number.

Path Parameters

Name Required Type Description
number required string The account number

Response

When account exists.

Status: 200 Success

Body:

{
  "account": {
    "balance": "R$ 520.00",
    "number": "1234"
  }
}

When account does not exist.

Status: 404 Not Found

Body:

{
  "error": {
    "message": "Unable to find account with number 1234."
  }
}

POST /api/accounts/transfer

🔐 Authenticated

Transfer the given amount from source account to destination account.

Parameters

Name Required Type Description
source_account_number required string Source account to withdraw amount
dest_account_number required string Destination account to deposit amount
amount required float The amount to be transferred

Response

When all transfer validation are met.

Status: 201 Created

Body:

{
  "message": "Successfully transferred amount to destination account.",
  "dest_account_number": "1235",
  "source_account_number": "1234",
  "amount": "R$100.00"
}

When a transfer validation like source account does not have enough funds to transfer fails.

Status: 422 Unprocessable entity

Body:

{
  "error": {
    "source_account": [
      "does not have enough funds to transfer"
    ]
  }
}

About

Simple Banking API implementation with Elixir and Phoenix

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages