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, likePUTandDELETE.)- Status codes tell you how it went:
200OK,404not found,500the 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?
- It worked
- The thing you asked for wasn't found
- The server crashed
- 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.