Mobile App Development
Lesson 3 of 3 9 min +70 XP

Data & APIs

Talking to a server.

What you'll learn

  • Explain what an API is
  • Describe a request/response cycle
  • Handle loading and error states
Phoning the warehouse

A weather app doesn't know the forecast itself — it phones a distant server (an API) and asks. Talking to APIs is how apps fetch fresh data, so your screen shows today's weather, not last week's.

Apps rarely work alone

An API (application programming interface) is a contract for talking to a server: send a request, get a response, usually as JSON. Because the network takes time and can fail, a good app shows a loading state while it waits and an error state if the request fails.

Three states, always

Every network call has three outcomes to design for: loading, success (show the data), and error (show a retry). Forgetting the error state is the most common bug.

Lab · Design the states
  1. An app fetches a list of messages from an API.
  2. What should the screen show while waiting?
  3. What should it show if the request fails?

What you should see: Show a spinner while loading, the messages on success, and a friendly 'Couldn't load — retry' on error. All three states must be handled.

Knowledge Check

+18 XP / correct

1. An API is…

2. Which state do developers most often forget to handle?