Skip to content

API Reference

Endpoint

GET /api/hits/:id/:resource[.format]
SegmentDescription
:idNamespace / owner identifier, e.g. github
:resourceCounter name, e.g. my-repo
.formatOptional. .json (default) or .svg

Counters are stored in Cloudflare KV under the key hits:<id>:<resource> and increment on every request.


JSON Response

Request

GET /api/hits/github/my-repo
GET /api/hits/github/my-repo.json

Response 200 OK

json
{ "count": 42 }
HeaderValue
Content-Typeapplication/json
Cache-Controlno-cache, no-store, must-revalidate
Access-Control-Allow-Origin*

SVG Response

Request

GET /api/hits/github/my-repo.svg
GET /api/hits/github/my-repo.svg?theme=moebooru-h

Response 200 OK — an inline SVG image with embedded base64 digit images.

HeaderValue
Content-Typeimage/svg+xml
Cache-Controlno-cache, no-store, must-revalidate
Access-Control-Allow-Origin*

Query Parameters

ParameterTypeDefaultDescription
themestringmoebooruVisual theme for the SVG counter. Falls back to moebooru if the value is unknown.

Available Themes

ThemeFormatPreview
moebooruGIFAnimated pixel-art characters (0–9)
moebooru-hPNGAlternative moebooru character set

SVG Structure

The generated SVG follows the same structure as Moe Counter:

  • <defs> contains one <image> element per unique digit (base64 data URI), avoiding duplicate blobs for repeated digits.
  • <g> contains <use> elements that reference the defs by digit character — efficient and spec-compliant.
  • image-rendering: pixelated is applied via <style> to preserve pixel art quality.
  • Dark-mode: @media (prefers-color-scheme: dark) applies filter: brightness(.6).

Error Responses

StatusBodyCause
400{ "error": "Missing id or resource" }Route params not strings
400{ "error": "Invalid resource" }Resource segment failed regex parse
400{ "error": "Unsupported format" }Format extension is neither json nor svg