This project implements a secure, real-time transaction processing system using FastAPI, OAuth2, and JWT.
Ensure you have the required packages installed:
pip install -r requirements.txtStart the FastAPI server using uvicorn:
python -m uvicorn app.main:app --reloadThe API will be available at http://127.0.0.1:8000.
- Open your browser and go to
http://127.0.0.1:8000/docs. - Click the Authorize button and enter:
- Username:
admin - Password:
admin123
- Username:
- Now all protected routes are accessible!
- Try the
POST /transactionsendpoint with a sample JSON:{ "user_id": "user_001", "amount": 150.50, "currency": "USD", "description": "Payment for services" }
Step 1: Get Token
curl -X 'POST' \
'http://127.0.0.1:8000/token' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'username=admin&password=admin123'Step 2: Submit Transaction (Using the token from Step 1)
curl -X 'POST' \
'http://127.0.0.1:8000/transactions' \
-H 'accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN_HERE' \
-H 'Content-Type: application/json' \
-d '{
"user_id": "user_001",
"amount": 100,
"currency": "USD"
}'