API stands for Application Programming Interface.
At its core, an API is a bunch of code that takes an input and gives you predictable outputs.
Think of an API as a middleman that enables applications to interact without needing direct access to each other's code or database.
Almost every digital service you use today—social media, e-commerce, online banking, ride-hailing apps—all of them are a bunch of APIs working together.
Examples:
"New York"
), the API returns the current temperature, humidity, and weather conditions.sorted()
API – If you provide a list of numbers ([5, 3, 8, 1]
), the API returns the sorted list ([1, 3, 5, 8]
).When engineers build APIs, they clearly define what inputs the API accepts and what outputs it produces, ensuring consistent behavior across different applications.
APIs follow a simple request-response model:
Every API requires specific types of inputs, and passing incorrect data can result in errors.
For example: If you tried putting your name into the Google Maps API as an input, that wouldn’t work very well.
Some APIs also require inputs in a specific format.
Example: The Currency Exchange API might need the input as "USD_TO_EUR"
instead of "usd to euro"
.
APIs often validate inputs to ensure they are correct before processing them, which helps maintain accuracy and security.
Just as APIs require specific inputs, they also return well-structured outputs.
For example, the Google Maps API always returns coordinates in the same format.
If the API can’t find the location, it provides an error response explaining why.
The apps you use every day—whether it's Gmail, Instagram, Uber, or Spotify—are essentially a collection of APIs with a polished user interface (UI) on top.
Most applications follow the frontend/backend architecture, where:
Let’s break this down with a real-world example: Uber.
Before the Uber app existed as a sleek, user-friendly experience, the company first built the core APIs that power ride-hailing services:
These APIs run on Uber’s servers, forming the backend infrastructure. Every time you request a ride, track your driver, or make a payment, these backend APIs handle the request.
Backend engineers are responsible for optimizing these APIs, improving ride-matching algorithms, securing transactions, and ensuring a smooth experience for millions of users.
The backend APIs handle all the complex logic, but they only work through code—which isn't practical for everyday users. That’s why companies build a frontend (user interface) on top of these APIs, allowing users to interact with the system visually and intuitively.
Example: When you enter your pickup & destination address, the frontend sends an API request to find nearby drivers and displays available cars.
Once the trip is complete, the frontend may call the process payment API to display the receipt.
APIs come in different forms depending on who can access them, how they are used, and what purpose they serve.
Open APIs, also known as Public APIs, are accessible to external developers with minimal restrictions.
Companies provide these APIs to encourage third-party developers to integrate their services and build new applications on top of them.
Normally, when you use the YouTube app, it makes internal API calls to fetch your video feed, search for content, or post comments. However, YouTube also provides a public API that allows developers to access some of this functionality outside of the app.
For example, the YouTube Search API allows developers to fetch video results based on a keyword. If you send a request to the API with "machine learning tutorial"
as the search term, it will return a structured response (JSON format) containing a list of relevant videos, including titles, descriptions, thumbnails, and video links.
This is incredibly useful because it enables developers to build custom applications on top of YouTube.
Internal APIs, also known as Private APIs, are designed exclusively for internal use within an organization. Unlike Open APIs, these are not accessible to external developers and are used to facilitate seamless communication between different internal systems within a company.
Let’s take Amazon as an example. When you place an order, you might assume that a single system processes your request. In reality, multiple internal APIs (order processing, inventory, payment, logistics etc..) work together behind the scenes to fulfill your order efficiently.
Each of these APIs operates independently, but they communicate through well-defined protocols to ensure a smooth and efficient process.
Internal APIs allow companies to break down their applications into smaller, manageable services, making it easier to scale. Developers can reuse internal APIs across different projects, reducing duplication and speeding up development.
The first two types of APIs we discussed—Open APIs and Internal APIs—are functional and serve real-world use cases like fetching weather data or booking a ride.
But there’s another category of APIs that developers use daily: Code Interfaces (also called Library APIs or Programming APIs).
These APIs don’t connect different applications; instead, they provide predefined functions within a programming language or framework to make development easier.
Example: Python’s built-in list API
When working with lists, Python provides a set of built-in functions (methods) to manipulate data.
Instead of writing sorting algorithms from scratch, developers can use sort()
or sorted()
in Python.
Code APIs are not just limited to built-in programming language functions. Take TensorFlow, an AI/ML library. It provides a high-level API for training machine learning models without needing to implement complex mathematical operations from scratch.
For example, creating a neural network using TensorFlow's API is as simple as:
Programming APIs abstract away complexity so that developers can focus on building solutions rather than reinventing the wheel.
APIs communicate using different protocols and architectures that define how requests are sent, how responses are formatted, and how data is exchanged between systems.
REST is the most widely used API communication method today. It is lightweight, stateless, and scalable, making it perfect for web services and mobile applications.
REST APIs follow a set of design principles and use HTTP methods (GET, POST, PUT, DELETE) to perform operations.
REST APIs are based on resources, and each resource is accessed through a URL (endpoint). The API follows the client-server model, meaning the client sends a request, and the server processes it and sends a response.
Retrieve a list of books (GET Request):
Response (JSON):
SOAP is an older API communication method that relies on XML-based messaging.
Unlike REST, which is lightweight, SOAP is more structured and secure, making it ideal for banking, healthcare, and enterprise applications.
SOAP messages are sent using XML format and require a WSDL (Web Services Description Language) file, which defines the API's available functions and request structure.
Request: Fetching account balance
Response:
GraphQL is an alternative to REST that allows clients to request exactly the data they need, making it more efficient for modern applications. Unlike REST, which requires multiple API calls to fetch related data, GraphQL can fetch all necessary data in a single request.
Instead of predefined endpoints, GraphQL exposes a single API endpoint, and the client sends queries to request specific fields.
Example: Fetching a user's profile and their recent posts in a single request.
Response:
gRPC (Google Remote Procedure Call) is a high-performance API communication method that uses Protocol Buffers (Protobuf) instead of JSON or XML, making it faster and more efficient.
gRPC uses binary data format instead of text-based formats, reducing payload size and it supports bidirectional streaming, meaning the client and server can send data at the same time.
Using an API might seem complex at first, but it follows a simple request-response pattern.
Here’s a guide on how to find, access, and interact with an API step by step:
Before using an API, you need to identify the right API for your needs. APIs are available for different services like weather data, finance, social media, etc.
Public API directories:
Official API Documentation:
API documentation explains how to use the API, available endpoints, authentication, and response formats.
Example: The OpenWeatherMap API
The OpenWeatherMap API allows users to fetch real-time weather data. Here's a breakdown of its key components:
API URL
Required Parameters:
q
: City name (e.g., London
)appid
: API Key (required for access)Most APIs require authentication to prevent unauthorized access and manage usage limits.
Example: Getting an API Key (OpenWeather API)
GET "https://api.openweathermap.org/data/2.5/weather?q=London&appid=YOUR_API_KEY"
Before writing code, test the API to see how it responds.
https://api.openweathermap.org/data/3.0/weather?q=London&appid=YOUR_API_KEY
).You can also test APIs directly from the command line using cURL.
curl -X GET "https://api.openweathermap.org/data/3.0/weather?q=New+York&appid=YOUR_API_KEY"
Now that you’ve tested the API, it’s time to integrate it into your application.
requests.get(url)
– Sends an API request.response.json()
– Converts response to JSON.if response.status_code == 200
– Checks if the request was successful.APIs don’t always return perfect responses. You should handle:
Once you fetch data from an API, you can display it dynamically in a web or mobile app.
Example: You can build a weather dashboard using the OpenWeatherMap API.