Corbin MeierCorbin Meier

API

/api/clicks

A minimal API for a single global click counter. It supports GET to read the current count and POST to increment the count by one.

GET

Request: GET /api/clicks

Response (200):

{
  "count": 42,
  "lastClick": "2025-10-07T15:13:00.000Z",
  "lastHourCount": 128,
  "last24hCount": 2345,
  "source": "db"
}

POST

Request: POST /api/clicks

Body (application/json):

{ "action": "Increment-Count" }

Response (200):

{ "count": 43 }

Invalid requests will return a 400 with an error object, for example: {"error":"invalid action"}

Example fetch

// read
fetch('/api/clicks')
  .then(r => r.json())
  .then(data => {
    console.log('total:', data.count);
    console.log('last click:', data.lastClick);
    console.log('last hour:', data.lastHourCount);
    console.log('last 24h:', data.last24hCount);
  })

// increment
fetch('/api/clicks', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ action: 'Increment-Count' }),
})
  .then(r => r.json())
  .then(data => console.log('updated total:', data.count));