Likes Tracking API

A cross-origin API service that tracks likes using unique IDs.

Features

  • Simple ID-based tracking - Use any unique identifier (blog posts, products, comments, etc.)
  • Embeddable widget - Drop-in script that creates beautiful like buttons
  • Real-time updates - Like counts update instantly across all websites
  • CORS enabled - Works from any website or domain
  • SQLite storage - Reliable, persistent data storage

Quick Start

1. Add the script to your page

<script src="https://jamesllllllllll--019894a514b47659ac14319f8b619533.web.val.run/script.js"></script>

2. Add a likes widget anywhere on your page

<div data-likes-id="your-unique-id"> <button class="likes-button">ā¤ļø <span class="likes-count">0</span></button> </div>

šŸ’” Customize the emoji: Change ā¤ļø to any emoji you want: šŸ‘ šŸŽ‰ šŸš€ ⭐ šŸŽÆ šŸ† šŸŽŠ šŸŽˆ šŸŽ

3. Done!

  • Loads current like count automatically
  • Handles button clicks to record likes
  • Updates count in real-time
  • Supports multiple IDs on one page

API Endpoints

POST /api/like

Record a like for a specific ID:

{ "id": "life-universe-everything" }

Returns:

{ "success": true, "id": "life-universe-everything", "likeCount": 42 }

GET /api/likes/:id

Get like count for a specific ID:

GET /api/likes/post-123

Returns:

{ "id": "post-123", "likeCount": 42 }

GET /api/likes

Get total likes across all IDs (for fun)

Use Cases

  • Blog posts: Use post IDs like "post-123" or "2024-01-15-intro"
  • Products: Use product IDs like "product-abc" or "laptop-xps-13"
  • Comments: Use comment IDs like "comment-456" or "reply-789"
  • Custom: Any unique identifier you want to track likes for!

Example Usage

Basic like tracking

// Get current likes for a post fetch('https://jamesllllllllll--019894a514b47659ac14319f8b619533.web.val.run/api/likes/post-123') .then(res => res.json()) .then(data => { document.querySelector('.likes-count').textContent = data.likeCount; }); // Record a like fetch('https://jamesllllllllll--019894a514b47659ac14319f8b619533.web.val.run/api/like', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: 'post-123' }) }) .then(res => res.json()) .then(data => { // Update the likes count });

Project Structure

ā”œā”€ā”€ backend/
│   └── database.ts          # SQLite database setup and queries
ā”œā”€ā”€ frontend/
│   └── index.html           # Documentation & demo
ā”œā”€ā”€ script.js                # Embeddable likes widget script
ā”œā”€ā”€ index.ts                 # Main HTTP handler using Hono
└── README.md                # This file