APIs and JSON

How programs ask other programs for things.

An API (application programming interface) is a menu of things a program is allowed to ask another program for. On the web, you ask with an HTTP request and get a response.

  • GET: fetch something. POST: send something new. (There are others, like PUT and DELETE.)
  • Status codes tell you how it went: 200 OK, 404 not found, 500 the server had a problem.
  • Data usually comes back as JSON, a simple text format of keys and values.
{
  "name": "croo",
  "stargazers_count": 7,
  "topics": ["cli", "ai"]
}

JSON: curly braces for objects, square brackets for lists, quotes around keys.

Let's make a real request. This one asks GitHub's public API about a repository:

Quick check

A request comes back with status 404. What happened?

  1. It worked
  2. The thing you asked for wasn't found
  3. The server crashed
  4. You were hacked

Answer: The thing you asked for wasn't found. 404 means not found. 5xx codes (like 500) are the server's problems, and 2xx codes mean success.