6.1. APIs#
6.1.1. What Is an API?#
API stands for Application Programming Interface.
An API is a way to programmatically interact with a applications or other software.
A document that describes how an API behaves is called the API specification.
Actual software that meets the specification is said to implement or expose an API.
APIs are written by software developers so that other developers can extend or interact with their software.
APIs are used by almost every piece of software we use on a daily basis. For example an graphical application on your computer uses APIs provided by the operating system to create windows and draw to the screen.
6.1.2. What Is a Web API?#
A web API is an API that works over the web using the HTTP protocol.
Web APIS allow communication between clients such as web browsers, desktop and mobile apps with a server.
Web APIs are now a staple of software. You likely use apps on your computer or mobile phone that rely on web APIs.
For example
Social media apps like Facebook, Twitter, Reddit, Instagram, Tiktok etc download user posts and upload submissions using a web API
Communication apps like Slack or Discord use a web API to synchronise messages
Weather apps use a Web API to retrieve the current weather and latest weather forecast
6.1.3. How Do Web APIs Work?#
Web APIs use HTTP requests and responses to exchange data with an API server.
However, the data exchanged is not HTML
The data is usually plaintext but formatted as JSON or XML
6.1.4. What is JSON?#
JSON stands for JavaScript Object Notation.
It’s a lightweight, human-readable format for storing and exchanging data.
Example
The example below shows a JSON “Object”, which is like a dictionary, of a student. You can also find various other data types that are supported in JSON like strings, arrays and numbers.
{
"name": "Alex",
"age": 17,
"skills": ["Python", "HTML"],
"address": {
"city": "Sydney",
"postcode": "2000"
}
}