One API for the web, iOS and Android

A website, an iOS app and an Android app can all use one backend. They reach it through an API. The server does not care which one is calling.

You place a dinner order in the food delivery app on an iOS phone. A friend opens the same app on an Android phone. A third person uses the delivery site in a laptop browser. All three see the same menu, the same prices and the same order status.

iOS appOne client
Android appA second client
WebsiteA third client
The app's serverHolds the data once
Think first. The delivery company adds an app for smartwatches. Which parts of its backend must be rewritten?
For a backend with an API, none of it is rewritten. A system that returns finished web pages needs much more work. Ask students to explain the difference after the step "A system with no API".

Select each client and compare the two boxes. The request changes with the client, and the reply from the server stays the same.

→
One API
GET /api/menu
Every client calls the same URL.
→
One database
One set of tables and one copy of the data
What this client sends Differs

What the server sends back Same

The menu as JSON, a plain text format for data. Every client receives the same reply.

More detail

The two messages as text

What this client sends
What the server sends back

The code each client uses

The code this client uses to ask
The code this client uses to show the result

What is different about this client

What REST stands for

REST stands for Representational State Transfer. The server holds the data. When a client asks for it, the server sends a representation of that data, which here is JSON text. What the client does with it is up to the client: a table, a list, a scrolling view in a phone app, or a printout. The server never needs to know.

Some systems are server-rendered. They return finished web pages, with the data mixed into the layout. A phone app cannot use that page directly. Compare what each kind of system returns.

Server-rendered system HTML

Returns a finished web page. The data is mixed into the layout.

API JSON

Returns only the data. Each app decides how it looks.

More detail

The two replies

What a server-rendered system returns HTML
What an API would return JSON

The same data in two forms

All the data a mobile app needs is in the HTML reply, mixed with table widths, CSS class names (labels that control appearance) and a decision about column order. An iOS app cannot use that reply directly. It would have to scrape it, which means reading HTML written for a browser and hoping the layout never changes. The layout changes often.

Why teams build it this way

With one kind of client, browsers only, server-rendered HTML was the fastest correct design. The cost shows up years later, when a second kind of client arrives and there is nothing for it to call. Adding an API later means going into the page-generating code and pulling the business logic (the rules for what the system does) out of the markup. Teams often keep the old design because it still works.

For a server-rendered system, a new app could reuse much less. There is no separate layer that an app could call, because the data and the layout are mixed in one reply. Ask students how much of the backend a new app could reuse before they open the comparison.

Phone users update their apps when they choose to, and some never do. An additive change adds a field. A breaking change renames or removes one. Choose Breaking and drag the slider to see who fails.

Who is on which version
updated to the new version still running the old one
What kind of change did you ship?

You can now decide whether an API change is safe for old apps.

More detail

Rule for changing an API

If you cannot update the clients, add freely and remove almost never. When you must break something, publish the new version at a new path (/api/v2/menu) and keep the old one running until few users remain on old versions. Another option is to keep the old field next to the new one and stop documenting it.

The adoption curves are illustrations of typical patterns. They do not come from measurements of a specific app.