APIIntermediate · 9 min · Updated May 4, 2026
API Client Setup
Organize fetch wrappers for maintainable data access.
Client function
Create a typed client helper for consistent request handling.
fetch helper
ts
export async function api<T>(url: string): Promise<T> {
const res = await fetch(url);
if (!res.ok) throw new Error('Request failed');
return res.json() as Promise<T>;
}