An API (Application Programming Interface) is like a waiter at a restaurant. You tell it what you want, and it brings you the data.But APIs do more than just fetch information. They’re the bridges that connect your code to other systems. With APIs, you can:
Pull customer data from your CRM (Salesforce, HubSpot)
Get order information from Shopify or WooCommerce
Send messages through Slack or email services
Use AI models from OpenAI or Anthropic
In the context of AI, APIs are essential. They let you connect AI capabilities to real business data and systems.
Let’s get real weather data using a free weather API:
Copy
import requests# We need coordinates to get weather datalatitude = 48.85 # Paris latitudelongitude = 2.35 # Paris longitude# Build the API URL with our parametersurl = f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}¤t=temperature_2m"# Make the requestresponse = requests.get(url)data = response.json()print(data)
The temperature is nested inside current, so to get it:
Copy
temperature = data['current']['temperature_2m']print(f"Temperature in Paris: {temperature}°C")# Output: Temperature in Paris: 20.0°C
What is JSON? JSON (JavaScript Object Notation) is just a way to structure data, similar to CSV or Excel files. While CSV stores data in rows and columns, JSON uses key-value pairs like Python dictionaries.
You send a request to the API’s URL with parameters (like coordinates)
The API processes your request and finds the data
You receive JSON data back with the information
You extract the specific parts you need
The pattern is always the same: connect to an API, send requests, get data back, use it in your code. APIs are how modern software talks to each other.