You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A counter API for counting visitors, clicks or anything you want.
Usage
Important
It is recommanded to deploy your own instance of counter by cloing this project. The Worker deployed on https://counter.kynsonszetau.com is not intended for public use and counters created maybe deleted without prior notice.
Simply send a GET request to any path. The counter will be incremented, and the latest value after the increment will be returned in JSON. Each path is a separate counter, which makes counting different things a piece of cake.
If a counter is no longer needed, send a DELETE request to the corresponding path to delete it. Note that deleting a counter requires authentication with bearer token.
Deploying your Own Counter
Important
Cloudflare Wokers Paid plan is required to use Durable Objects.
git clone this project
Update wrangler.toml to match your needs (e.g. routes). Remember to uncomment the [[migrations]] section before the first deployment.
Generate a random base64-encoded token
Hash the token with SHA-512 and encode the hash with base64
Upload the hash with wrangler secret put DELETE_TOKEN_HASH
Deploy the worker with npm run deploy
How it works
This API is powered by Cloudflare Workers and Durable Objects. A globally unique counter object will be created when a GET request hits a path for the first time and initialize the counter. Any subsequence GET request will increment the counter for that path. Durbale Objects ensures there is only one running instance for each counter, each increment can be considered atomic.
Acknowledgement
This project is based on Cloudflare's Atomic Counter example.
About
A counter API for counting visitors, clicks or anything you want.