Developers · Website menu
Connect a website menu to Hare POS
Your website keeps its own menu. Hare reads it, and can send name and price changes back, so the café changes a price once. You build three things: a menu feed, a ping after each Publish, and (for two-way sync) one signed endpoint. Plain HTTPS and JSON, in any language.
Before you start
The café owner finds these on Hare's Website menu page (Back office › Catalogue › Website menu), before or after connecting.
HARE_PING_URL | Where to POST after each Publish (part 2). |
HARE_CONNECTION_ID | Your website's id at Hare (part 3). |
HARE_PUBLIC_KEY | <kid>:<key>, to check Hare's signature (part 3). Two, comma-separated, during a key rotation. |
1 · Serve your menu feed
Publish your live menu as JSON at a public https address, and point to it from your menu page's <head> with <link rel="alternate" type="application/vnd.hare.menu+json" href="/menu.json">. The owner pastes either address into Hare.
{
"format": "hare-menu-feed", "formatVersion": 1, "menuVersion": 44,
"publishedAt": "2026-12-06T03:14:05Z", "currency": "AUD", "pricesIncludeGst": true,
"capabilities": ["read", "write"], "writeUrl": "/api/hare/menu", "maxPrices": 2,
"sections": [{ "id": "drinks", "title": "Drinks", "groups": [{
"id": "coffee", "title": "", "items": [{
"id": "drinks-flat-white", "name": "Flat White", "description": "",
"prices": [{ "label": "Regular", "cents": 520 },
{ "label": "Large", "cents": 600 }]
}]
}]}]
}
- Ids are stable and never reused for something else; item ids are how Hare links each item to the POS.
- Prices are integer cents, GST inclusive, 0 to
maxPricesof them in display order. No prices means "price set at sale". menuVersionrises on every Publish. Send anETagand answerIf-None-Matchwith 304.- Up to 2,000 items and 2 MB. Unknown fields are ignored, so you can add your own.
- List
"write"andwriteUrlonly onceHARE_CONNECTION_IDandHARE_PUBLIC_KEYare set (part 3).
2 · Ping Hare after every Publish
An empty POST to HARE_PING_URL tells Hare to read your feed now. Never let it slow down or fail a Publish: send it after the response, with a 5 second timeout and no retry. A 429 is fine to ignore. Without the ping, Hare still catches up within 15 minutes.
fetch(process.env.HARE_PING_URL, { method: "POST", signal: AbortSignal.timeout(5000) })
.catch(() => {});
3 · Take changes from Hare
Optional, and needed for the café to set prices on the POS or both ways. Hare POSTs a batch of changes to your writeUrl, signed with its Ed25519 key. Check the signature before you read the body, and answer 401 with no detail if any step fails:
- Parse
Hare-Signature: v1; kid=…; ts=…; sig=…. Split each part on its first=only. - Find the key for
kidinHARE_PUBLIC_KEY. An unknown kid fails. - Fail if the timestamp is more than 300 seconds from your clock.
- Verify
sig(base64url; accept it with or without=padding) over the four lines below. - Fail if the body's
connectionIdisn't yourHARE_CONNECTION_ID.
v1
{ts}
{your HARE_CONNECTION_ID}
{lowercase hex SHA-256 of the raw request body}
POST /api/hare/menu
Hare-Signature: v1; kid=hare-2026-12; ts=1765000000; sig=<base64url signature>
{
"connectionId": "<your HARE_CONNECTION_ID>",
"baseMenuVersion": 44,
"state": { "direction": "both", "linkedIds": ["drinks-flat-white"] },
"changes": [
{ "op": "set", "id": "drinks-flat-white", "field": "prices", "from": [520, 600], "to": [550, 630] },
{ "op": "add", "ref": "6f1c…", "section": { "id": "drinks" }, "group": { "newTitle": "Tea" },
"item": { "name": "Chai Latte", "description": "", "prices": [{ "label": "Regular", "cents": 580 }] } },
{ "op": "move", "id": "drinks-milkshake", "section": { "id": "drinks" }, "group": { "id": "shakes" } },
{ "op": "remove", "id": "lunch-banana-bread" }
]
}
setchanges one field (nameorprices) only if its current value equalsfromexactly.addcreates an item with an id you choose. The samerefmust return the same id, never a second item: keep a ref → id map.moveplaces an item in another section and group;removetakes it off the menu. Sections and groups come as{ id }or{ newTitle }.statesays which items are shared with the POS. Store it beside your content: with"pos", lock those items' names and prices in your admin.
Apply every change you can to your current live menu as one Publish, then answer 200 with one result per change, in order:
{
"menuVersion": 45,
"results": [
{ "status": "applied" },
{ "status": "applied", "id": "drinks-chai-latte" },
{ "status": "conflict", "current": "Iced Milkshake" },
{ "status": "not_found" }
]
}
| status | when |
|---|---|
applied | Done. For an add, also return the new id. |
conflict | The field no longer equals from; return its value now as current. |
not_found · invalid | No such item, or the change breaks your own rules (with a message). |
400 for a malformed body, 401 for any signature problem, 5xx for anything else: Hare retries after 1, 5 and 15 minutes.
4 · Reference code
A complete TypeScript version for a Next.js website, from a café website that runs it. Copy it and write the two parts that are yours: getMenu() and applyChanges(). In another language, follow parts 1 to 3 and check your code with part 5.
lib/hare/config.tsThe three variables
// The three values from Hare's Website menu page. Read at call time, so a redeploy with new
// values needs no code change.
export const hareConfig = {
pingUrl: () => process.env.HARE_PING_URL?.trim() ?? "",
connectionId: () => process.env.HARE_CONNECTION_ID?.trim() ?? "",
publicKeys: () => process.env.HARE_PUBLIC_KEY?.trim() ?? "",
};
/** Offer "write" only when both are set: Hare then sends signed changes to /api/hare/menu. */
export function hareCanWrite(): boolean {
return Boolean(hareConfig.connectionId() && hareConfig.publicKeys());
}
lib/hare/signature.tsParse and check Hare-Signature
// Checks Hare's request signature. Hare signs with its Ed25519 key; the website holds only the
// public key, so neither side's data gives write access on its own.
//
// Hare-Signature: v1; kid=hare-2026-12; ts=1765000000; sig=<base64url signature>
// signed string: "v1\n{ts}\n{connectionId}\n{lowercase hex SHA-256 of the raw body}"
import { createHash, createPublicKey, verify, type KeyObject } from "node:crypto";
export const MAX_SKEW_SECONDS = 300;
type Header = { kid: string; ts: number; sig: string };
export function parseSignatureHeader(header: string | null): Header | null {
if (!header) return null;
const [version, ...parts] = header.split(";").map((p) => p.trim());
if (version !== "v1") return null;
const fields = new Map<string, string>();
for (const part of parts) {
const eq = part.indexOf("="); // split on the first "=" only, so padding in sig survives
if (eq > 0) fields.set(part.slice(0, eq).trim(), part.slice(eq + 1).trim());
}
const kid = fields.get("kid");
const ts = fields.get("ts");
const sig = fields.get("sig");
if (!kid || !sig || !ts || !/^\d{1,12}$/.test(ts)) return null;
return { kid, ts: Number(ts), sig };
}
/** HARE_PUBLIC_KEY is "<kid>:<SPKI base64>", two of them comma-separated during a key rotation. */
export function parsePublicKeys(value: string): Map<string, KeyObject> {
const keys = new Map<string, KeyObject>();
for (const entry of value.split(",").map((e) => e.trim()).filter(Boolean)) {
const colon = entry.indexOf(":");
if (colon <= 0) continue;
try {
const der = Buffer.from(entry.slice(colon + 1).trim(), "base64");
const key = createPublicKey({ key: der, format: "der", type: "spki" });
if (key.asymmetricKeyType === "ed25519") keys.set(entry.slice(0, colon).trim(), key);
} catch {
// an entry that does not parse is left out
}
}
return keys;
}
export function signedString(ts: number, connectionId: string, body: Uint8Array): string {
const digest = createHash("sha256").update(body).digest("hex");
return ["v1", String(ts), connectionId, digest].join("\n");
}
/** True only for a fresh, valid signature by a configured key over this body and connection. */
export function verifyHareSignature(input: {
header: string | null;
body: Uint8Array;
connectionId: string; // this website's own HARE_CONNECTION_ID
keys: Map<string, KeyObject>;
now?: number; // milliseconds since the epoch
}): boolean {
const { header, body, connectionId, keys, now = Date.now() } = input;
if (!connectionId) return false;
const parsed = parseSignatureHeader(header);
if (!parsed) return false;
const key = keys.get(parsed.kid);
if (!key) return false;
if (Math.abs(now / 1000 - parsed.ts) > MAX_SKEW_SECONDS) return false;
try {
// Node's "base64url" decoder accepts the signature with or without "=" padding.
const signature = Buffer.from(parsed.sig, "base64url");
return verify(null, Buffer.from(signedString(parsed.ts, connectionId, body)), key, signature);
} catch {
return false;
}
}
lib/hare/ping.tsThe ping
// The ping after each Publish: an empty POST, so Hare reads the feed within seconds. It must never
// slow down or fail a Publish: call it after the response (Next.js: after(() => pingHare())).
import { hareConfig } from "./config";
export async function pingHare(): Promise<void> {
const url = hareConfig.pingUrl();
if (!url) return;
try {
await fetch(url, { method: "POST", body: "", cache: "no-store", signal: AbortSignal.timeout(5_000) });
} catch {
// Hare catches up at its next 15-minute check; a 429 (rate limit) is fine to ignore too.
}
}
app/menu.json/route.tsThe feed
// GET /menu.json: the Hare Menu Feed v1. Point to it from the menu page's <head>:
// <link rel="alternate" type="application/vnd.hare.menu+json" href="/menu.json">
import { hareCanWrite } from "@/lib/hare/config";
import { getMenu } from "@/lib/menu"; // yours: the live menu, with a version that rises on every Publish
export async function GET(request: Request): Promise<Response> {
const menu = await getMenu();
const etag = `"v${menu.version}"`;
const headers = { ETag: etag, "Cache-Control": "public, no-cache" };
if (request.headers.get("if-none-match") === etag) return new Response(null, { status: 304, headers });
const canWrite = hareCanWrite();
return Response.json(
{
format: "hare-menu-feed",
formatVersion: 1,
menuVersion: menu.version,
publishedAt: menu.publishedAt,
currency: "AUD",
pricesIncludeGst: true,
capabilities: canWrite ? ["read", "write"] : ["read"],
...(canWrite ? { writeUrl: "/api/hare/menu" } : {}),
maxPrices: 2,
sections: menu.sections.map((s) => ({
id: s.id, // stable, never reused
title: s.title,
groups: s.groups.map((g) => ({
id: g.id,
title: g.title,
items: g.items.map((i) => ({
id: i.id,
name: i.name,
description: i.description ?? "",
hidden: false,
tags: [],
prices: i.prices.map((cents, n) => ({ label: n === 0 ? "Regular" : "Large", cents })),
})),
})),
})),
},
{ headers },
);
}
app/api/hare/menu/route.tsThe write endpoint (applyChanges is yours)
// POST /api/hare/menu: name and price changes from Hare POS. Guarded by Hare's signature and this
// website's Connection ID: 401 with no detail for any signature problem, 400 for a malformed body,
// 500 for anything else (Hare retries).
import { after } from "next/server";
import { applyChanges } from "@/lib/menu"; // yours: apply the batch as one Publish (see below)
import { hareConfig } from "@/lib/hare/config";
import { pingHare } from "@/lib/hare/ping";
import { parsePublicKeys, verifyHareSignature } from "@/lib/hare/signature";
const MAX_BODY_BYTES = 1024 * 1024;
const status = (code: number) => new Response(null, { status: code });
export async function POST(request: Request): Promise<Response> {
const body = new Uint8Array(await request.arrayBuffer());
if (body.byteLength > MAX_BODY_BYTES) return status(413);
const connectionId = hareConfig.connectionId();
const signed = verifyHareSignature({
header: request.headers.get("hare-signature"),
body,
connectionId,
keys: parsePublicKeys(hareConfig.publicKeys()),
});
if (!signed) return status(401);
let json: { connectionId?: unknown; changes?: unknown; state?: unknown };
try {
json = JSON.parse(new TextDecoder().decode(body));
} catch {
return status(400);
}
if (json.connectionId !== connectionId) return status(401);
if (!Array.isArray(json.changes) || typeof json.state !== "object") return status(400);
try {
// applyChanges is yours. For each change, in order:
// set: change one field (name or prices) only if it still equals "from"; else "conflict"
// add: create the item (same "ref" → same id, never a second item); return its new id
// move: place the item in another section and group
// remove: take it off the menu
// Store json.state beside your content (it says which items are shared with the POS).
// Publish once if anything changed, and return { menuVersion, results: [...one per change] }.
const { published, menuVersion, results } = await applyChanges(json);
if (published) after(() => pingHare());
return Response.json({ menuVersion, results });
} catch (error) {
console.error("A change from Hare POS failed:", error);
return status(500);
}
}
5 · Test your signature check
Point your check at these test values and run the six cases. Hare signs them just now, with a test key that signs nothing real, so they always match what Hare sends.
Loading the test cases...
6 · Go live
- Set
HARE_PING_URL,HARE_CONNECTION_IDandHARE_PUBLIC_KEYin production. - Deploy the feed and the write endpoint. Open your feed: it lists
"write". - The owner connects in Hare with the menu page's address. Both ways is offered straight away (already connected? they press Check again).
- Change a price on the POS: it shows on your website within about 10 seconds.
Hare Menu Feed v1 (formatVersion 1) · last updated