A lightweight Cloudflare Worker API for users, medications and user medication records.
https://d1.timdurrant.com
Protected endpoints require this HTTP header:
Authorization: Bearer YOUR_API_TOKEN
Do not expose your API token inside public frontend JavaScript. If a browser app needs to call this API directly, consider putting the Worker behind Cloudflare Access.
Shows this API documentation page.
Basic health check.
curl https://d1.timdurrant.com/health
Example response:
{
"ok": true,
"name": "D1 Medication API"
}
Returns all users.
curl https://d1.timdurrant.com/users \ -H "Authorization: Bearer YOUR_API_TOKEN"
Creates a user.
Request body:
{
"name": "Tim"
}
Example request:
curl -X POST https://d1.timdurrant.com/users \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"Tim"}'
Returns all medications.
curl https://d1.timdurrant.com/medications \ -H "Authorization: Bearer YOUR_API_TOKEN"
Creates a medication.
Request body:
{
"name": "Panadol",
"quantity": 24
}
Example request:
curl -X POST https://d1.timdurrant.com/medications \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"Panadol","quantity":24}'
Returns all user medication records, including joined user and medication names.
curl https://d1.timdurrant.com/user-medications \ -H "Authorization: Bearer YOUR_API_TOKEN"
Creates a user medication record.
Request body:
{
"user_id": 1,
"medication_id": 1,
"quantity_per_day": 2,
"date_dispensed": "2026-07-04"
}
Example request:
curl -X POST https://d1.timdurrant.com/user-medications \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"user_id":1,"medication_id":1,"quantity_per_day":2,"date_dispensed":"2026-07-04"}'
Updates part or all of a user medication record.
Example request:
curl -X PATCH https://d1.timdurrant.com/user-medications/1 \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"quantity_per_day":1.5}'
Deletes a user medication record.
curl -X DELETE https://d1.timdurrant.com/user-medications/1 \ -H "Authorization: Bearer YOUR_API_TOKEN"
name must not be empty.quantity must be a non-negative integer.quantity_per_day must be greater than zero.date_dispensed must use YYYY-MM-DD format.user_id and medication_id must be positive integers.