A simple banking API built with Rust, Actix Web, and SQLx for PostgreSQL.
It supports user registration, authentication (JWT), balance management, and transactions.
- User registration and login (with password hashing)
- JWT-based authentication
- Account balance tracking
- Credit and debit transactions
- View transaction history
- RESTful API structure
- Logging middleware
- Rust (https://rustup.rs)
- PostgreSQL (local or Docker)
- sqlx-cli (for running migrations)
-
Clone the repository:
git clone https://github.com/vickyone0/banking-api.git cd banking-api -
Set up environment variables:
Create a
.envfile in the project root:DATABASE_URL=postgres://postgres:password@localhost/banking JWT_SECRET=your_jwt_secret -
Run database migrations:
sqlx migrate run
-
Build and run the server:
cargo run
The API will be available at http://localhost:8080.
POST /api/register— Register a new userPOST /api/login— Login and receive a JWT
GET /api/profile— Get user profilePUT /api/profile— Update user profilePOST /api/transactions— Create a transaction (credit/debit)GET /api/transactions— List user transactionsGET /api/balance— Get account balance
Run unit tests with:
cargo testRegister:
curl -X POST http://localhost:8080/api/register \
-H "Content-Type: application/json" \
-d '{"username":"testuser","email":"[email protected]","password":"password123"}'Login:
curl -X POST http://localhost:8080/api/login \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"password123"}'Create Transaction (requires JWT):
curl -X POST http://localhost:8080/api/transactions \
-H "Authorization: Bearer <JWT_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"amount":1000,"transaction_type":"credit","description":"Deposit"}'src/
├── auth/ # JWT and middleware
├── models/ # Database models
├── routes/ # API route handlers
├── main.rs # Application entry point
└── ...
migrations/ # SQLx migration scripts
MIT
Contributions welcome!