A Django + Django REST Framework application for registering API endpoints, running automated health checks, storing results, and viewing a live dashboard with uptime percentages and response-time history.
- Django & Django REST Framework
- PostgreSQL
requestsfor HTTP checksdjango-environfor environment configuration- Django templates + Chart.js for the dashboard UI
-
Clone the repository
git clone <your-repo-url> cd DjangoAPI
-
Create and activate a virtual environment
python -m venv venv # Windows .\venv\Scripts\Activate.ps1 # macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
Copy
.env.exampleto.envand fill in real values:copy .env.example .env # Windows cp .env.example .env # macOS/Linux
Required variables:
DB_NAME,DB_USER,DB_PASSWORD,DB_HOST,DB_PORT— PostgreSQL connectionSECRET_KEY— Django secret keyRUN_CHECKS_SECRET_KEY— secret for the external cron trigger endpoint
-
Create the PostgreSQL database
Ensure PostgreSQL is running and create a database matching
DB_NAME(default:api_db). -
Run migrations
python manage.py migrate
-
Create a superuser (required for admin and API write access)
python manage.py createsuperuser
-
Start the development server
python manage.py runserver
- Dashboard: http://127.0.0.1:8000/
- Admin: http://127.0.0.1:8000/admin/
- API root: http://127.0.0.1:8000/api/
python manage.py check_endpointsThis checks all active endpoints and prints a summary to stdout.
The POST /api/run-checks/ endpoint runs the same logic as the management command. It is protected by the X-RUNNER-KEY header, which must match RUN_CHECKS_SECRET_KEY in your .env.
Example request:
curl -X POST http://127.0.0.1:8000/api/run-checks/ \
-H "X-RUNNER-KEY: your-run-checks-secret-key-here"Successful response:
{"checked": 3}- Deploy the app so it is reachable on the public internet.
- Create a free account at cron-job.org.
- Add a new cron job:
- URL:
https://your-domain.com/api/run-checks/ - Method: POST
- Schedule: e.g. every 5 minutes
- Custom header:
X-RUNNER-KEY: <your RUN_CHECKS_SECRET_KEY value>
- URL:
- Save and enable the job.
| Endpoint | Methods | Auth |
|---|---|---|
/api/endpoints/ |
GET (public), POST/PUT/PATCH/DELETE (staff) | Staff for writes |
/api/endpoints/{id}/stats/ |
GET (public) | None |
/api/checks/ |
GET (public) | None |
/api/run-checks/ |
POST | X-RUNNER-KEY header only |
- Single-user / single-tenant: no visitor login or multi-project support.
- Checks use a 10-second timeout and compare the HTTP status code to
expected_status_code. - Uptime percentage is calculated over the last 50 checks per endpoint.
- Chart.js is loaded from the jsDelivr CDN (requires internet access in the browser).