Skip to content

Chapter 1.1: What is an API and why is it needed?

Study time: 30 minutes


1. Introduction: API as a "space docking port"

Imagine you are the commander of a spaceship. To connect your ship to the ISS, you need a standard docking port. Without it, docking is impossible, even if the ship and the station are a perfect match.

API (Application Programming Interface) is the same "docking port" for programs. - It is a set of rules that allows different applications to exchange data and work together. - Example: when a mobile application shows the weather forecast, it uses the API of a weather service.

💡 Analogy from space: An API is like a communication protocol between Earth and a Mars rover. The rover receives commands in a format it understands (e.g., "take a photo of the crater"), performs the task, and sends the data back.


2. Why are APIs needed?

  1. Simplifying development Instead of creating everything from scratch, you use a ready-made API, like the SpaceX API.

    # Example: Getting data about SpaceX launches
    import requests
    response = requests.get("https://api.spacexdata.com/v3/missions")
    print(response.json()[0])  # Output data
    

  2. Process automation APIs allow robotic probes to automatically transmit data to Earth without manual intervention.

  3. System integration Like docking modules of the ISS: an API connects your application with payment systems, databases, or even telescopes!

  4. Access to unique data For example, the SpaceX API provides real data on rocket launches.


3. How does an API work?

  • The client (your program) sends an HTTP request to the server.
  • The server (e.g., NASA) processes the request and returns a response in JSON format.
  • The data is "space treasures": ISS coordinates, photos of galaxies, a list of exoplanets.

⚡ Example of a request to the "Open Notify" API (ISS):

curl "http://api.open-notify.org/iss-now.json"
Response:
{
  "message": "success",
  "timestamp": 1725431234,
  "iss_position": {
    "latitude": "51.1234",
    "longitude": "-120.5678"
  }
}


4. Types of APIs (Brief overview)

Type Example from space Where it is used
REST Standard communication "MCC ↔ satellite" Web services (90% of cases)
GraphQL "Custom request" (e.g., "give only the size and mass of the planet") Complex systems
SOAP Like radio encryption in old missions Enterprise applications

In this tutorial, we will focus on REST API - the most popular format.


5. Examples of space APIs

  1. NASA Open API: Data on asteroids, photos from the Hubble telescope.
  2. SpaceX API: Information about launches, rockets, Dragon ships.
  3. Open Notify: Current position of the ISS, number of people in space.

Interactive quiz

1. An API is...

2. Why use an API instead of writing your own code?

3. What data format does an API most often return?


🚀 Chapter summary:

An API is the foundation for working with data from external sources. Just as an astronaut cannot work without communication with the MCC, a developer cannot build a complex application without an API. In the next chapter, we will learn how to send "commands" to the server using HTTP methods!

📌 Hint: Try making a request to the Open Notify API and find out where the ISS is now! (You can do this even with a simple console)