This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Val Town project that implements a likes tracking API using unique IDs with the following structure:
index.ts exports app.fetch as the HTTP handlerstevekrouse/sqlite)likes_by_id_v1 (increment version when changing schema)initDatabase(), recordLike(), getAllLikes(),
getLikeCount(), getTotalLikes()id (TEXT PRIMARY KEY), likes (INTEGER), created_at, updated_at/ (documentation page), POST /api/like (record like),
GET /api/likes/:id (get count for specific ID), GET /api/likes (all data)id field (string)# Run/test the application locally deno run --allow-net --allow-read index.ts # Lint code deno lint # Format code deno fmt # Type checking deno check index.ts
When modifying the database schema, increment the table name (e.g.,
likes_by_id_v1 → likes_by_id_v2) rather than using ALTER TABLE
operations.
The API is designed for cross-origin requests. Example usage from any website:
// Record a like for a specific content ID
fetch("https://your-val-url.val.run/api/like", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
id: "post-123", // Any unique identifier
}),
})
.then((res) => res.json())
.then((data) => console.log("New like count:", data.likeCount));
// Get like count for a specific ID
fetch("https://your-val-url.val.run/api/likes/post-123")
.then((res) => res.json())
.then((data) => console.log("Like count:", data.likeCount));
Uses Val Town utility functions for proper file serving:
import {
readFile,
serveFile,
} from "https://esm.town/v/std/utils@85-main/index.ts";
Include this pattern in Hono apps for better error visibility:
app.onError((err, c) => {
throw err;
});
The API includes CORS headers to allow requests from any origin:
app.use(
"*",
cors({
origin: "*",
allowMethods: ["GET", "POST", "OPTIONS"],
allowHeaders: ["Content-Type"],
}),
);
noImplicitAny: false,
strict: false)https://esm.sh for npm packages and https://esm.town/v/
for Val Town utilities<script src="https://esm.town/v/std/catch"></script> for client-side error
capture