A minimal Cloudflare Worker that accepts a string over HTTP and saves it to a D1 database, so you can check it later with a query or a curl.
POST /save— save a string- JSON body:
{ "value": "some string" } - or raw text body with any other content-type
- optional auth: if
SAVE_TOKENsecret is set, sendAuthorization: Bearer <token>
- JSON body:
GET /entries— returns the last 50 saved entries as JSON
This repo is zero-touch: import it into the Cloudflare dashboard (Workers & Pages → Create → Import a repository) and deploy. No manual D1 setup is needed.
wrangler.tomlomitsdatabase_id, so Wrangler auto-provisions a new D1 database namedsimple-worker-alpha-dband binds it asDBon first deploy.- The Worker itself creates the
entriestable on first request (seeensureSchema()insrc/index.js), so there's no separate migration step.
If deploying from the CLI instead of the dashboard:
npm install
# (optional) set a shared secret so only your server can POST
npx wrangler secret put SAVE_TOKEN
# deploy (auto-provisions the D1 database; table is created on first request)
npm run deployThe db:create / db:migrate:* scripts are kept only as a manual fallback if you ever want an explicit, pre-populated database instead of relying on auto-provisioning + lazy table creation.
# save a string
curl -X POST https://simple-worker-alpha.<your-subdomain>.workers.dev/save \
-H "Content-Type: application/json" \
-d '{"value":"hello world"}'
# with auth enabled
curl -X POST https://simple-worker-alpha.<your-subdomain>.workers.dev/save \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"value":"hello world"}'
# read entries back
curl https://simple-worker-alpha.<your-subdomain>.workers.dev/entriescurl -X POST https://simple-worker-alpha.<your-subdomain>.workers.dev/save \
-H "Content-Type: application/json" \
-d "{\"value\":\"$(curl -s ifconfig.me)\"}"
curl https://simple-worker-alpha.<your-subdomain>.workers.dev/entriesnpm run db:migrate:local
npm run dev