Skip to content
CribScore
Skip to content
CribScore Docs

Recipes

TypeScript Starter

TypeScript starter — native `fetch`, env-driven auth, error-shaped responses. Drops into Next.js, Cloudflare Workers, or Node.

Setup#

Use native `fetch`. No SDK required. Centralize the base URL + auth header in one helper and keep call sites focused on shape.

Helpertypescript
const API_BASE = "https://api.cribscore.co";

async function cribscore<T>(path: string, init: RequestInit = {}): Promise<T> {
  const response = await fetch(`${API_BASE}${path}`, {
    ...init,
    headers: {
      Authorization: `Bearer ${process.env.CRIBSCORE_API_KEY}`,
      "Content-Type": "application/json",
      Accept: "application/json",
      ...(init.headers ?? {}),
    },
  });

  if (!response.ok) {
    throw new Error(`CribScore ${path} failed: ${response.status} ${await response.text()}`);
  }

  return (await response.json()) as T;
}

Trust read#

Trust tier roll-up. Cache for an hour with Next.js `unstable_cache` or your framework's equivalent — trust state changes on the day-scale, not the second-scale.

Trusttypescript
const response = await fetch("https://api.cribscore.co/v1/trust/jurisdictions?limit=25", {
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
  },
});

const { data } = await response.json();
for (const jurisdiction of data) {
  console.log(jurisdiction.state_code, jurisdiction.trust_tier);
}

Decision memo#

POST request, JSON body. Wire the result into a route handler or a server action — the response is small enough to return directly.

Memotypescript
const memo = await fetch("https://api.cribscore.co/v1/decision/memo", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    geography: "90003",
    child_age_months: 24,
    budget_weekly: 350,
    shortlist_limit: 3,
    priorities: ["safety_score", "license_status", "commute_minutes"],
  }),
}).then((r) => r.json());

console.log(memo.summary);