BankingMockAPI#
Getting Started#
Prerequisites#
Installation#
- Clone the repository:
git clone <repo-url> cd BankingMockAPI - Install dependencies:
npm install
Running the Server#
With Node.js#
node server.js
The server will start on http://localhost:3001 by default.
With Docker#
docker build -t banking-mock-api .
docker run --name banking-mock-api -d -p 3001:3001 banking-mock-api
Same as mentioned aboe the api will be available at on http://localhost:3001
Use following commands to stop or start the container:
docker container stop banking-mock-api
docker container start banking-mock-api
API Endpoints#
Authentication#
POST /login#
Authenticate user and receive JWT and refresh token.
- Body:
{ "username": "test@test.test", "password": "password@123" } - Response:
{ "token": "<JWT>", "refreshToken": "<refresh_token>" }
POST /refresh-token#
Get a new JWT using a refresh token.
- Body:
{ "refreshToken": "<refresh_token>" } - Response:
{ "token": "<new_JWT>", "refreshToken": "<new_refresh_token>" }
Accounts#
GET /accounts#
Get all accounts for the authenticated user.
- Headers:
Authorization: Bearer <JWT>
- Response:
[ { "id": 1, "user_id": 1, "name": "Checking", "balance": 1500.5 }, ... ]
Cards#
GET /cards#
Get all cards for the authenticated user.
- Headers:
Authorization: Bearer <JWT>
- Response:
[ { "id": 1, "user_id": 1, "number": "4111111111111111", "expiry": "12/26", "cvv": "123" }, ... ]
Transactions#
GET /transactions#
Get transactions for the authenticated user, with search, sort, and pagination.
- Headers:
Authorization: Bearer <JWT>
- Query Parameters:
search(optional): Search by description or typesort(optional): Field to sort by (default:date)order(optional):ascordesc(default:desc)page(optional): Page number (default:1)limit(optional): Items per page (default:10)
- Response:
[ { "id": 1, "user_id": 1, "account_id": 1, "amount": -50.25, "type": "debit", "description": "Grocery Store", "date": "2024-06-01T10:00:00Z" }, ... ]
Default Test User#
- Username:
test@test.test - Password:
password@123
Database#
- The SQLite database is used.
- The database is reset and seeded with test data every time the server starts.