A simple API built with FastAPI for processing and managing loan applications. It features per-country rate limiting, a personal ID blacklist, and endpoints to view submitted applications.
- Loan Application Submission: Endpoint to apply for a new loan.
- Application Retrieval: Endpoints to list all submitted applications or retrieve applications by a specific personal ID.
- Blacklist: Rejects applications from predefined blacklisted personal IDs.
- Rate Limiting: Implements a simple in-memory rate limiter that restricts requests to 3 per second from the same country.
FYI: The country is identified via the client's IP address using the ip-api.com service. If the IP geolocation service is unavailable or fails, the system defaults to country code "GB".
- Python 3.8 or higher
-
Clone the repository:
git clone https://github.com/aulanchik/loan-manager-api.git cd loan-manager-api -
Install dependencies: The project uses
pyproject.tomlto manage dependencies. Install them using pip:pip install .This will install FastAPI, Uvicorn, and other necessary packages.
To run the development server, use Uvicorn:
uvicorn app.main:app --reloadThe API will be available at http://127.0.0.1:8000.
Submits a new loan application.
- URL:
/apply-loan - Method:
POST - Request Body:
{ "loan_amount": 1000.0, "term": 12, "name": "John", "surname": "Doe", "personal_id": "1234567890" } - Success Response (
200 OK):{ "status": "approved", "country": "GB" } - Error Responses:
400 Bad Request: If thepersonal_idis on the blacklist.429 Too Many Requests: If the rate limit for the client's country is exceeded.
Retrieves a list of all stored loan applications.
- URL:
/loans - Method:
GET - Success Response (
200 OK):[ { "application": { "loan_amount": 1000.0, "term": 12, "name": "John", "surname": "Doe", "personal_id": "1234567890" }, "country": "GB" } ]
Retrieves all loan applications associated with a specific personal ID.
- URL:
/loans/{personal_id} - Method:
GET - Example URL:
/loans/1234567890 - Success Response (
200 OK): Returns a list of loan applications matching thepersonal_id.
The project uses pytest for testing. To run the test suite, execute the following command from the project's root directory:
pytest