StoicBuilder

HandbookII the ForumAPI calls

IIthe Forum, The shape of an app

API calls

1 min readUpdated 28 November

In plain words

An API call is a message your app sends to a server at a specific address, asking it to fetch, save or change something, then waiting for the reply.

Where you see it

Open DevTools, go to the Network tab and reload Chirp: each row is an API call, such as GET /api/posts. Click one to see what went out and what came back.

src/lib/posts.tsbrowser
export async function getPosts() { const res = await fetch("/api/posts"); if (!res.ok) throw new Error(`Loading posts failed: ${res.status}`); return res.json();}
fetch sends the request. The res.ok check turns a failed call into an error instead of an empty feed.

What goes wrong

  1. Not checking whether the call worked

    fetch only throws when the network itself fails. A 500 from your server still counts as a reply, so without a check the screen quietly shows nothing.

    const posts = await (await fetch("/api/posts")).json();
  2. No loading or error state

    The page says "No posts yet" while the call is still on its way, or forever if it failed. People read that as their data being gone.

  3. A call that fires on every render

    A useEffect with no dependency list, the [] at the end, runs after every redraw, and each reply triggers another redraw. The loop hammers your database and can use up a free plan's limits in minutes.

    useEffect(() => { loadPosts().then(setPosts); });

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
For every API call on this page, check the response status, show a loading state while waiting and a clear message if it fails. Then list which address each call goes to and what it sends.

Quick check

Sign in to earn +10 XP for it

Chirp's feed shows "No posts yet", but the database holds 300 posts. Where do you look first?

Got a prompt that touches API calls?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.