API client

The one object every screen uses to call the API. It owns the base URL, JSON, the bearer header, typed errors for HTTP failures, the silent token refresh and rate-limit handling, so screens never call fetch directly.

Minimal example

ts
export const api = new ApiClient(API_URL, tokenStore);
const page = await api.request<Page<Restaurant>>("/v1/restaurants?lat=28.46&lng=77.03");

Learn this concept

Lesson 4.6 · Single-flight API refresh

Used in exercises

Exercise 4.7 · API client and auth screens Exercise 4.10 · Restaurant list screen Exercise 4.16 · Cart screen Exercise 4.20 · API request retry utility Exercise 8.5 · Expo stretch integration
Prerequisite conceptsTokenStore