Requests and Responses

What this is. An API is a way for one program to ask another program for something. On the web that almost always means: you send an HTTP request to an address, and you get back data rather than a page.

That is the whole idea. A web page is for a person; an API response is for a program.

Why this matters more than it sounds. Almost nothing useful is built from data you produced yourself. Weather, transit times, prices, library catalogues, census figures, museum collections: all of it lives somewhere else, and an API is how you reach it.

The skill is not the request. Anyone can write the request in ten minutes. The skill is everything around it: understanding what came back, what is missing, what it is safe to conclude, and how to behave on someone else's infrastructure.

Same data, two audiences

HTML

<!-- for a person -->
<article>
  <h2>Kindred</h2>
  <p>Published 1979</p>
</article>

JSON

// for a program
{
  "title": "Kindred",
  "year": 1979
}
Compare → The left is shaped for reading. The right is shaped for using. An API returns the right, which is why you can build something new with it rather than only display it.

You are a guest

Nearly every API you use in this course is free and run by a library, a museum, a government or a volunteer. Someone pays for that server. Requesting politely, caching what you fetch, and identifying yourself are not optional courtesies; on several archives they are conditions of use.

Mark this lesson complete

Your progress is saved on this device. No account needed.

Next: The Parts of a Request
← Back