APIs
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    What is an API?: the 60-second story

    What is an API?

    Your charger never asks where tonight’s power comes from.

    It relies only on the socket’s shape, voltage, fuse and meter. Behind the wall, the grid can be rebuilt.

    An API is a contract. Callers never see the code behind it.

    So you can swap MySQL for PostgreSQL, split a monolith or add a cache. If the contract holds, no caller notices.

    Is the JSON the contract?

    Bad: Fields and types

    Teams agree on every field yet disagree on meaning. Paise or rupees?

    Good: Shapes plus promises

    Semantics, guarantees, limits, auth, lifecycle. Most bugs hide in what nobody wrote down.

    The API says 201 Created. Has any money moved?

    No. The payment exists, but stays pending until the payer approves in their UPI app. The app polls, or waits for a webhook.

    ≈9×

    faster: one screen-shaped call, not ten

    Assume 80 ms per mobile round trip and 1 ms inside the data centre. Ten dependent calls from the phone: 800 ms. One call doing them server-side: 90 ms.

    Your list never promised an order. It just came back newest first. Then you change it.

    Hyrum’s Law

    With enough users, someone depends on every observable behaviour. A caller skipped sorting; now it breaks.

    Add an optional field: safe. Rename one: old apps break.

    To an old client, a rename is a removal. It finds amount_paise missing and shows ₹0 or crashes. You can’t force it to upgrade.

    Change a published API without breaking it

    1. Only add: optional fields, new endpoints
    2. Clients ignore fields they don’t recognise
    3. A true break gets /v2, run side by side
    4. Retire with Deprecation and Sunset headers, then brownouts

    Remember

    An API is a contract — operations, shapes, errors and promises like idempotency and limits — that hides the implementation. Change it only by adding, because callers depend on everything they can see.