Getting started

Quick start

Make your first request in five minutes.

Create a client

Create one client per API and share it. Put it in its own module so every import reuses the same cache.

ts
// lib/api.tsimport { createClient } from "tempo-http";export const api = createClient({  baseUrl: process.env.API_URL,  headers: { Authorization: `Bearer ${process.env.API_TOKEN}` },});

Make a request

ts
import { api } from "./lib/api";type Post = { id: number; title: string };const posts = await api.get<Post[]>("/posts", { query: { limit: 10 } });const created = await api.post<Post>("/posts", { body: { title: "Hello" } });

Next steps

  • Read every option of createClient.
  • Tune retry for flaky upstreams.
  • Turn on caching for read-heavy endpoints.

Was this page helpful?

Updated