Skip to content

Kounter is a tiny webservice that works as a counter 🧮

Notifications You must be signed in to change notification settings

kerolloz/kounter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kounter 🧮 fastify Railway

Kounter is a simple counter service that can be used in various ways.
Use cases include a profile views counter, repository visits counter, or anything you want to count.

Development

For development, you must set the DETA_PROJECT_KEY environment variable to your Deta project key.
This project uses Bun for development.

bun dev

Docs

Kounter is built using Fastify.
It has a straightforward API with the following few endpoints.

Note

You can also check the Swagger API documentation for more details.

Endpoints

Base URL: https://kounter.kerolloz.dev

GET /

Redirects to this repository.


GET /badge/:key

  • Increments the counter by 1 if :key exits; creates a new counter with count initialized to 1 otherwise.
  • Returns a shields.io badge (SVG image) for your counter.
Parameters
  • key - The key of the counter to increment.
Query Parameters
  • silent - Set to true to disable incrementing the counter. Defaults to false.
  • style - Set the style of the badge. Can be one of flat, flat-square, for-the-badge, or plastic. Defaults to flat.
  • label - Set the left-hand-side text. Defaults to :key.
  • color - Set the background of the right part (hex, rgb, rgba, hsl, hsla and css named colors supported). Defaults to brightgreen.
  • labelColor - Set the background of the left part (hex, rgb, rgba, hsl, hsla and css named colors supported). Defaults to grey.
  • cntPrefix - Set prefix to display before the counter value. Defaults to "" empty string.
  • cntSuffix - Set suffix to display after the counter value. Defaults to "" empty string.
Examples

![badge](https://kounter.kerolloz.dev/badge/kerolloz.kounter)
badge

![badge](https://kounter.kerolloz.dev/badge/kerolloz.kounter?style=flat-square&color=blue&silent=true)
badge

![badge](https://kounter.kerolloz.dev/badge/kerolloz.kounter?label=kerolloz/kounter&labelColor=white&cntPrefix=visits%20&silent=true)
badge

![badge](https://kounter.kerolloz.dev/badge/kerolloz.kounter?label=&color=333&style=for-the-badge&cntSuffix=%20Views&silent=true)
badge


GET /count/:key

Try it
  • Returns the current count for :key without incrementing it.
  • Returns { key: ":key", count: 0 } if the counter :key does not exist.
Parameters
  • key - The key of the counter to get count value for.
Example
$ curl -X GET https://kounter.kerolloz.dev/count/xyz

{
  "count": 1,
  "key": "xyz"
}