This project is a simple RESTful API built with Django and Django REST Framework for the HNG Internship Stage 0 Backend Task. The API serves personal profile data and integrates with a third-party service to provide a random cat fact with each request.
The live, deployed application can be accessed here: https://hngprofileproject-zichdan7442-tho7lc5q.leapcell.dev/
This project successfully implements all the core requirements of the task:
- A working GET
/me/endpoint is accessible and returns a 200 OK status. - The response structure strictly follows the required JSON schema.
- All required fields (
status,user,timestamp,fact) are present. - The
userobject containsemail,name, andstackfields with valid string values. - The
timestampfield returns the current UTC time in ISO 8601 format and updates dynamically with every request. - The
factfield contains a cat fact fetched live from the Cat Facts API. - A new cat fact is fetched on every request (not cached).
- The response
Content-Typeheader isapplication/json. - The code is well-structured and follows best practices for the Django stack.
- Robust logging and error handling are implemented for the external API call.
- The project includes interactive API documentation via Swagger UI.
This project includes interactive API documentation generated with drf-yasg (Swagger UI). The documentation allows for easy exploration and testing of the endpoint directly in the browser.
API Docs URL: https://hngprofileproject-zichdan7442-tho7lc5q.leapcell.dev/
- Endpoint:
/me/ - Method:
GET - Description: Retrieves the user's profile information and a random cat fact.
- Success Response (200 OK):
{ "status": "success", "user": { "email": "zichdan1999@gmail.com", "name": "Daniel Ezichi Okorie", "stack": "Python/Django" }, "timestamp": "2025-10-20T12:00:00.123456Z", "fact": "A cat can jump up to five times its own height in a single bound." } - Error Handling: If the external Cat Facts API fails, the
factfield will contain a descriptive error message, ensuring the endpoint remains stable.{ // ... other fields "fact": "Error: The request to the Cat Facts API timed out." }
- Backend: Django, Django REST Framework
- Web Server: Gunicorn
- API Documentation: drf-yasg (Swagger UI)
- Deployment: Leapcell
Follow these instructions to set up and run the project on your local machine.
- Python 3.8+
pipandvenv- Git
git clone https://github.com/zichdan/hng_profile_project.git
cd hng_profile_projectIt is highly recommended to use a virtual environment to manage project dependencies.
# For macOS/Linux
python3 -m venv venv
source venv/bin/activate
# For Windows
python -m venv venv
.\venv\Scripts\activateAll required packages are listed in the requirements.txt file.
pip install -r requirements.txtThis project uses environment variables for configuration. Create a .env file in the project's root directory. For this simple project, the key variables (SECRET_KEY and DEBUG) have safe defaults for local development.
You can now start the local development server.
python manage.py runserverThe application will be available at http://127.0.0.1:8000/.
For production deployment, the following environment variables are required. For local development, safe defaults are provided in settings.py.
| Variable | Description | Example Value |
|---|---|---|
SECRET_KEY |
The secret key for your Django application. | your-super-secret-django-key |
DEBUG |
Toggles Django's debug mode. Should be False in production. |
False |
ALLOWED_HOSTS |
Comma-separated list of trusted hostnames. | yourdomain.com,127.0.0.1 |
You can test the endpoint in several ways:
-
Via Swagger UI (Recommended):
- Run the server and navigate to
http://127.0.0.1:8000/. - Expand the
GET /me/endpoint. - Click the "Try it out" button, then "Execute".
- Run the server and navigate to
-
Via Browser:
- Simply navigate to
http://12-7.0.0.1:8000/me/in your web browser.
- Simply navigate to
-
Via
curl:- Open your terminal and run the following command:
curl http://127.0.0.1:8000/me/
- Open your terminal and run the following command:
- Name: Daniel Ezichi Okorie
- Email: zichdan1999@gmail.com