typescript+match-fetchtypescriptmatch-fetch
match-fetch consumer examples
How a TypeScript app uses @danrabydev/match-fetch: UserApi extends ApiBase, exhaustive FetchResult.match, and getJson. EXAMPLE_API_TOKEN is an optional env name; example.com is not a live API.
typescriptapp/src/main.ts
import { handleUser, UserApi } from "./api/users.ts";
const token = process.env.EXAMPLE_API_TOKEN;
const users = new UserApi("us", {
...(token ? { headers: { Authorization: `Bearer ${token}` } } : {}),
});
const name = handleUser(await users.user("1"));
console.log(name);