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.
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;
}Search#
Type the response shape inline or pull it from the OpenAPI generated client. Either path works.
const params = new URLSearchParams({ zip_code: "90003", limit: "5" });
const response = await fetch(`https://api.cribscore.co/v1/facilities?${params.toString()}`, {
headers: {
Authorization: "Bearer YOUR_API_KEY",
Accept: "application/json",
},
});
if (!response.ok) {
throw new Error(`CribScore search failed: ${response.status}`);
}
const { data } = await response.json();
console.log(data.map((facility: { id: string; name: string }) => facility.name));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.
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.
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);