count
count copied to clipboard
counting things, as microservice
A simple microservice for counting things.
Usage
You can count whatever you want. It's inspired by antirez.com and rauchg.com.
For seeing your counters, just perform a GET to /:collection/:key:
curl https://count.kikobeats.com/pageviews/culture-shipping
// => "204"
You can also getting counters in a bulk using a comma as separator:
curl https://count.kikobeats.com/pageviews/culture-shipping,professional-career
// => "204,98"
If you want to increment a counter, pass incr query parameter:
curl https://count.kikobeats.com/pageviews/culture-shipping?incr
// => "205"
It doesn't matter if your id contains final slash; it will be sanitized.
For printing the value in your website, a representative code for doing that could be:
<script>
fetch(`'https://count.kikobeats.com/pageviews/${window.location.pathname}?incr`)
.then(res => res.json())
.then(count => {
document.querySelector('.pageviews-container').classList.remove('display-none')
document.querySelector('.pageviews-count').textContent = count
})
</script>
Environment Variables
Authentication
DOMAINS
Required
Type: string|string[]
The list of allowed domains authorized to consume your Microlink API credentials.
Note domains should be provided in the URL.origin format (e.g., 'https://example.com').
Database
The service is backed at Upstash.
You need to create an account (it's free!) and copy some relevant values specified below.
UPSTASH_REDIS_REST_URL
Type: string
Your Upstash database URL to use.
UPSTASH_REDIS_REST_TOKEN
Type: string
Your Upstash token authentication-
License
count © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.
kikobeats.com · GitHub Kiko Beats · Twitter @Kikobeats