A secure REST API for managing SMS transaction data from a mobile money service, with comprehensive Data Structures & Algorithms (DSA) analysis.
This project implements a complete REST API solution that:
- Parses SMS transaction data from XML format
- Provides secure CRUD operations with Basic Authentication
- Demonstrates efficiency comparison between linear search and dictionary lookup algorithms
- Includes comprehensive API documentation and testing
rest-api-project/
├── api/ # REST API implementation
│ ├── rest_api.py # Main API server
│ └── test_api.py # API testing script
├── dsa/ # Data Structures & Algorithms
│ ├── xml_parser.py # XML parsing and JSON conversion
│ ├── search_comparison.py # DSA comparison implementation
│ └── main.py # Main DSA analysis script
├── docs/ # Documentation
│ └── api_docs.md # Complete API documentation
├── screenshots/ # Test screenshots (to be added)
├── modified_sms_v2.xml # Sample SMS transaction data
└── README.md # This file
- Basic Authentication implementation
- Secure credential validation
- CORS support for web applications
- Input validation and error handling
- GET
/transactions- List all transactions - GET
/transactions/{id}- Get specific transaction - POST
/transactions- Create new transaction - PUT
/transactions/{id}- Update existing transaction - DELETE
/transactions/{id}- Delete transaction
- Linear Search vs Dictionary Lookup comparison
- Performance analysis with timing measurements
- Complexity analysis (O(n) vs O(1))
- Memory usage evaluation
- Python 3.7 or higher
- No additional dependencies required (uses standard library)
-
Clone or download the project
cd rest-api-project -
Run the DSA analysis (optional)
python dsa/main.py
-
Start the API server
python api/rest_api.py --port 8000
-
Test the API (in another terminal)
python api/test_api.py
All API endpoints require Basic Authentication:
- Username:
admin - Password:
password123 - Header:
Authorization: Basic YWRtaW46cGFzc3dvcmQxMjM=
curl -X GET "http://localhost:8000/transactions" \
-H "Authorization: Basic YWRtaW46cGFzc3dvcmQxMjM="curl -X GET "http://localhost:8000/transactions/1" \
-H "Authorization: Basic YWRtaW46cGFzc3dvcmQxMjM="curl -X POST "http://localhost:8000/transactions" \
-H "Authorization: Basic YWRtaW46cGFzc3dvcmQxMjM=" \
-H "Content-Type: application/json" \
-d '{
"type": "deposit",
"amount": 75000,
"sender": "+250788111111",
"receiver": "+250788222222",
"timestamp": "2024-01-16T14:30:00Z",
"status": "completed",
"description": "New mobile deposit"
}'curl -X PUT "http://localhost:8000/transactions/1" \
-H "Authorization: Basic YWRtaW46cGFzc3dvcmQxMjM=" \
-H "Content-Type: application/json" \
-d '{
"amount": 100000,
"status": "completed",
"description": "Updated transaction"
}'curl -X DELETE "http://localhost:8000/transactions/1" \
-H "Authorization: Basic YWRtaW46cGFzc3dvcmQxMjM="The project includes a comprehensive analysis comparing two search algorithms:
- Time Complexity: O(n)
- Space Complexity: O(1)
- Use Case: When memory is limited or searches are infrequent
- Time Complexity: O(1) average case
- Space Complexity: O(n)
- Use Case: When frequent lookups are needed and memory is available
Based on testing with 25 transactions and 1000 iterations per test:
- Dictionary lookup is typically 10-50x faster than linear search
- The speedup increases with larger datasets
- Dictionary lookup provides consistent O(1) performance
Run the comprehensive test suite:
python api/test_api.pyUse curl commands or tools like Postman with the examples provided above.
- ✅ Authentication (valid/invalid credentials)
- ✅ All CRUD operations
- ✅ Error handling (404, 400, 401)
- ✅ Input validation
- ✅ JSON parsing
- Credentials transmitted in base64 (not encrypted)
- No session management or token expiration
- Hardcoded credentials (not suitable for production)
- No rate limiting or DoS protection
- JWT (JSON Web Tokens) - Stateless authentication with expiration
- OAuth 2.0 - Industry standard for API authentication
- HTTPS - Encrypt all communications
- Rate Limiting - Prevent abuse and DoS attacks
- Input Validation - Sanitize all inputs
- Audit Logging - Track all API access
Complete API documentation is available in docs/api_docs.md including:
- Detailed endpoint descriptions
- Request/response examples
- Error codes and handling
- Data models and validation rules
{
"id": 1,
"type": "deposit",
"amount": 50000,
"sender": "+250788123456",
"receiver": "+250788654321",
"timestamp": "2024-01-15T10:30:00Z",
"status": "completed",
"description": "Mobile money deposit"
}deposit- Money deposited into accountwithdrawal- Money withdrawn from accounttransfer- Money transferred between accountspayment- Payment to merchant or service
completed- Transaction successfully processedpending- Transaction in progressfailed- Transaction failed
- Response Time: < 10ms for most operations
- Throughput: 100+ requests/second (single-threaded)
- Memory Usage: ~2MB for 25 transactions
- Linear Search: O(n) - scales linearly with data size
- Dictionary Lookup: O(1) - constant time regardless of data size
- Memory Overhead: ~200 bytes for dictionary (25 entries)
The API provides comprehensive error handling:
- 400 Bad Request - Invalid input data
- 401 Unauthorized - Authentication required
- 404 Not Found - Resource not found
- 500 Internal Server Error - Server-side errors
- Follows PEP 8 Python style guidelines
- Comprehensive error handling
- Detailed documentation and comments
- Modular design for maintainability
- Easy to add new endpoints
- Pluggable authentication system
- Configurable data sources
- Scalable architecture
- Database Integration - Replace in-memory storage with database
- Advanced Authentication - Implement JWT or OAuth 2.0
- Rate Limiting - Add request throttling
- Caching - Implement Redis or similar caching layer
- Logging - Add comprehensive audit logging
- Monitoring - Add health checks and metrics
- API Versioning - Support multiple API versions
-
Port already in use
python api/rest_api.py --port 8001
-
XML file not found
- Ensure
modified_sms_v2.xmlis in the project root - Check file permissions
- Ensure
-
Authentication errors
- Verify credentials:
admin:password123 - Check base64 encoding:
YWRtaW46cGFzc3dvcmQxMjM=
- Verify credentials:
-
Import errors
- Ensure you're running from the project root directory
- Check Python path configuration
This project is created for educational purposes.
For questions or issues, please refer to the project documentation or contact the development team.
Note: This project demonstrates REST API development, security implementation, and data structures analysis. The Basic Authentication implementation is for educational purposes and should not be used in production environments without proper security enhancements.