API Design for Beginners / Chapter 1 — What Does an API Promise? (lessons 1–5) / Lesson 1

An API Is a Promise You Can't Take Back

Time needed: about 5 min (estimate)

☆ Read later

You can try the opening of this lesson without an account.

You can rename a function. You can't rename a JSON key

You can rename a variable in your code anytime with a find-and-replace.

You can't find-and-replace a JSON key you've exposed to the world.

That key isn't read by your code; it's read by someone else's app you've never seen.

API design is the work of deciding where to put these "no going back" parts.

Internal details vs. external promises

// Internal detail: change it as much as you like function buildNoteRow(record) { const t = record.headline; // ← nobody minds if you rename it to title tomorrow return { ...record, t }; } // External promise: once it's out, you can't take it back { "id": 1, "title": "Groceries", "tags": ["home"], "done": true } ↑ ↑ this name and this type become part of someone else's code the moment you publish

What breaks the other side?

Let's treat one client screen as a function called render and distort the response shape in four ways.

Only adding a field causes nothing to happen.

Renaming, removing, and changing a type all blow up inside the other side's code.

You can run this right in the browser.

editor.js

Tab indents. To leave the editor, press Esc, then Tab.

Create a free account to keep reading

With an account you can read the rest of this lesson, take the quiz, and read every free lesson in this course. Lessons you answer correctly are recorded as complete.

Report a problem with this lesson

Log in to send a report.

Keyboard shortcuts

Keys available in a lesson
KeyAction
[ or Alt + ←Go to the previous lesson
] or Alt + →Go to the next lesson
?Open this list
EscClose this list

The keys do not work while the cursor is in a code editor or an input field.