D1 Medication API

A lightweight Cloudflare Worker API for users, medications and user medication records.

Base URL

https://d1.timdurrant.com

Authentication

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.

Public endpoints

GET /

Shows this API documentation page.

GET /health

Basic health check.

curl https://d1.timdurrant.com/health

Example response:

{
  "ok": true,
  "name": "D1 Medication API"
}

Users

GET /users

Returns all users.

curl https://d1.timdurrant.com/users \
  -H "Authorization: Bearer YOUR_API_TOKEN"

POST /users

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"}'

Medications

GET /medications

Returns all medications.

curl https://d1.timdurrant.com/medications \
  -H "Authorization: Bearer YOUR_API_TOKEN"

POST /medications

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}'

User Medications

GET /user-medications

Returns all user medication records, including joined user and medication names.

curl https://d1.timdurrant.com/user-medications \
  -H "Authorization: Bearer YOUR_API_TOKEN"

POST /user-medications

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"}'

PATCH /user-medications/:id

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}'

DELETE /user-medications/:id

Deletes a user medication record.

curl -X DELETE https://d1.timdurrant.com/user-medications/1 \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Validation rules