This is a Django REST API that implements a dynamic profile endpoint as per the Backend Wizards Stage 0 Task.
- GET
/meendpoint returning user profile with dynamic cat facts - Fetches real-time cat facts from external API
- Dynamic UTC timestamp in ISO 8601 format
- Error handling for external API failures
- CORS enabled for cross-origin requests
- Rate limiting (10 requests per minute per IP)
- Logging for debugging and monitoring
- Redis cache backend for rate limiting (production-ready)
- Python 3.8 or higher
- Virtual environment (recommended)
-
Clone the repository:
git clone https://github.com/temmy669/HNG1.git cd HNG1 -
Create and activate virtual environment:
python -m venv venv # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile in the root directory with the following variables:URL=https://catfact.ninja/fact EMAIL=your-email@example.com NAME=Your Full Name STACK=Your Backend Stack -
Run migrations:
python manage.py migrate
-
Start the development server:
python manage.py runserver
The API will be available at http://127.0.0.1:8000/
Returns user profile information with a dynamic cat fact.
Rate Limit: 10 requests per minute per IP address
Response Format:
{
"status": "success",
"user": {
"email": "your-email@example.com",
"name": "Your Full Name",
"stack": "Your Backend Stack"
},
"timestamp": "2025-10-15T12:34:56.789Z",
"fact": "A random cat fact from the API"
}Error Response (Rate Limit Exceeded):
{
"status": "error",
"message": "Rate limit exceeded. Too many requests from your IP address.",
"retry_after_seconds": 60,
"error_code": "RATE_LIMIT_EXCEEDED"
}The API includes comprehensive documentation accessible through multiple formats:
Interactive API documentation with testing capabilities:
http://127.0.0.1:8000/api/docs/swagger/
Alternative documentation view with clean, responsive design:
http://127.0.0.1:8000/api/docs/redoc/
Raw OpenAPI 3.0 specification in JSON format:
http://127.0.0.1:8000/api/schema/
The documentation includes:
- Detailed endpoint descriptions
- Request/response schemas
- Example responses
- Rate limiting information
- Error response formats
- Django==5.2.7
- djangorestframework==3.16.1
- python-decouple==3.8
- django-cors-headers==4.9.0
- requests==2.32.5
- django-ratelimit==4.1.0
- django-redis==6.0.0
- redis (for production cache backend)
URL: Cat Facts API endpoint (default: https://catfact.ninja/fact)EMAIL: Your email addressNAME: Your full nameSTACK: Your backend technology stack
Test the endpoint using curl:
curl http://127.0.0.1:8000/meOr open in browser: http://127.0.0.1:8000/me
This API can be deployed to platforms like Railway, Heroku, or AWS. Ensure environment variables are set in your deployment platform's configuration.
For production deployment, update the cache configuration in settings.py to use Redis:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/1', # Update with your Redis URL
}
}Install Redis and update the LOCATION with your Redis connection string.