πΉ soyo β A fast, serverless API for fetching and caching social share counts using ShareThis, Cloudflare Workers, Hono, and KV storage. Includes scheduled updates, admin endpoints, and queue processing for scalable analytics.
- Fetch real-time social share counts for any URL via ShareThis
- π Data source: ShareThis Social Share Count API
- Cache share counts in Cloudflare KV for fast retrieval
- Admin endpoints to manage and list cached URLs
- Serverless architecture with Cloudflare Workers & Hono
- Scheduled cron jobs to refresh share counts
- Queue-based updates for scalability
- TypeScript + Zod for type safety and validation
This project uses ShareThis as its primary data provider for social share counts. ShareThis is a leading platform for social sharing and analytics. For more information, see the ShareThis Social Share Count API documentation.
βΉοΈ Note: All share count data is sourced from ShareThis.
GET /β ReturnsHello Worldfor health check
GET /share-count?url=...β Fetch live share counts for a URLGET /cached-share-count?url=...β Retrieve cached share counts from KV
GET /admin/urlsβ List all cached URLs and their share countsPOST /admin/urlsβ Add new URLs to be trackedDELETE /admin/urlsβ Remove URLs from trackingPOST /admin/update-allβ Manually update share counts for all cached URLs
Note: Admin endpoints require an
Authorization: Bearer <ADMIN_TOKEN>header.
- Cloudflare Workers
- Hono (web framework)
- TypeScript
- Zod (validation)
- Cloudflare KV (key-value storage)
- Cloudflare Queues (background processing)
- Wrangler (deployment & local dev)
# 1. Install dependencies
yarn install
# 2. Configure environment variables
cp .dev.vars.example .dev.vars # Edit as needed
# 3. Start local dev server
yarn dev
# 4. Deploy to Cloudflare
yarn deployADMIN_TOKENβ Secret token for admin endpointssoyo_kv_storeβ Cloudflare KV namespace bindingsoyo_queueβ Cloudflare Queue binding
Configure these in your .dev.vars or via Wrangler configuration.
curl 'https://<your-worker-url>/share-count?url=https://example.com'- Cron: Refreshes share counts every hour (
0 * * * *) via thescheduledhandler - Queue: Handles batch updates for URLs via the
queuehandler (internal, not exposed as HTTP endpoints)
src/
βββ index.ts # Main worker entry (routes, handlers)
βββ fetchShareThisCounts.ts # Fetch & validate share counts from ShareThis
wrangler.jsonc # Cloudflare Worker config
package.json # Project metadata & scripts
tsconfig.json # TypeScript config
PRs and issues welcome! Please open an issue to discuss major changes first.
MIT
- Maintained by Calpa Liu
Made with β€οΈ, Cloudflare, and πΉ Soyo!