I created this in order to count how many requests each IP is using, without sending personal data to CountAPI.xyz To accomplish this, I used Workers KV to map the IP address to a random UUID, which is used as the identifier on CountAPI.
Here's an example of what's stored in workers KV, with the user's IP as the key:
{
"userID": "5e64db68-d628-4938-9c01-0968a2f76861",
"userIP": "1.2.3.4",
"firstSeenDate": "2020-05-11T02:12:16.377Z",
"counterURL": "https://api.countapi.xyz/info/sldkfjsoiefsdf_users/5e64db68-d628-4938-9c01-0968a2f76861",
"meta": {
"cf": {
"first_country": "US",
"first_colo": "IAD",
"first_asn": 32780
}
}
}
Example api result calling api.countapi.xyz/info:
{
"namespace": "sldkfjsoiefsdf_users",
"key": "5e64db68-d628-4938-9c01-0968a2f76861",
"ttl": 15769870400,
"created": 1589163136907,
"update_lowerbound": -1,
"update_upperbound": 10000,
"enable_reset": false,
"value": 3630
}
"value" is the total number of requests that user has made.
Then, to view all of the data, you can use the Cloudflare API to list all of the keys, and then call the CountAPI using each user's UUID.