Skip to content
engineering workbench.by StudyPort Academy
Learning path
Advanced18 min

API versioning basics

Understand the idea

An API has to change without forcing every existing caller to change on the same day.

The idea

Callers ship slower than the server. If you rename a field on the only they have, their code fails on a day they did not plan a release. A version is a promise that one shape will keep working while another shape exists beside it. /v1/notes/7 keeps title. /v2/notes/7 adds done. Adding a field is usually safe for old parsers. Removing or renaming title is not. A path prefix is one tactic, not a complete strategy. The work is the promise, not the letter v.

What changes

What you can change without stranding a caller
ChangeOld callerWhat to do
Add a fieldIgnores itSafe on the same route, or fine in a new version
Rename a fieldReads undefinedKeep the old name on the old version
Remove a fieldLoses data it neededLeave the old route in place until callers move
Change a typeParses the wrong valueTreat it as a new version

The command

Version 1

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

Version 2

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

The mistake

Check the result

Version 1 returns title Milk and no done field. Version 2 returns title Milk and done false. Both can be true at the same time because they are different promises.

Guided challenge

Keep the v1 field name title

GET /v1/notes/7 currently returns name. Change the v1 handler so it still returns title: Milk for old callers.

Keep the v1 field name title

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

EXPECTED RESULT

status 200
{"title":"Milk"}

Hints 0/2

    Use all hints or make 3 failed checks (0/3).

    Free exploration

    Change this example and run it again. Each run is a new process. Nothing is saved.

    Your variation

    3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01Why keep /v1 after /v2 exists?
    02Which change is less likely to break a caller?

    Ready to call this one understood?

    Mark this lesson complete to earn 200 XP. You can always revisit it.

    Sign in to save progress
    Next lesson