APIs for Technical Sellers
Introduction to APIs
What Is an API?
Imagine you're at a restaurant. You want to order food, but you can't just walk into the kitchen and tell the chef what you want. Instead, you talk to a waiter. The waiter takes your order, communicates it to the kitchen, and brings the food back to you. You don't need to know how the kitchen works, only how to talk to the waiter.
An Application Programming Interface, or API, is like that waiter. It's a messenger that allows two different software applications to talk to each other. One application (you) sends a request for data or a specific action, and the API delivers that request to another application (the kitchen). Then, it brings the response back.
An API is a bridge that allows two software applications to talk to each other without you needing to know what’s happening behind the scenes.
This middleman role is crucial. Without APIs, software would be isolated. You couldn't use a travel app to book flights from different airlines, or log into a new website using your Google account. APIs create a standardized way for programs to share data and functionality, making our digital lives much more connected.
How APIs Work
For an API to work, it needs a clear set of rules and components, just like a waiter needs to know your table number and understand your order. These components define how requests and responses are handled.
Endpoint
noun
A specific URL where an API can be accessed. It's like the address for a particular resource or function.
Think of an endpoint as a specific table in the restaurant. If you want weather data, you'll send a request to the weather service's API at an endpoint like api.weatherservice.com/v1/current/new-york.
Once you have the right address, you need to tell the API what you want to do. This is done using methods.
| Method | Action | Example |
|---|---|---|
GET | Retrieve data | Get a user's profile information. |
POST | Create new data | Add a new user to a database. |
PUT | Update existing data | Change a user's email address. |
DELETE | Remove data | Delete a user's account. |
Finally, the data sent back and forth needs to be in a language both applications understand. This is where data formats come in. The most common format for modern APIs is JSON (JavaScript Object Notation), which is lightweight and easy for both humans and machines to read.
{
"user": {
"name": "Alex",
"email": "alex@example.com",
"id": 12345
}
}
Common Types of APIs
While all APIs serve as intermediaries, they aren't all built the same way. Different architectural styles and protocols exist, each with its own strengths. Here are three of the most common types you'll encounter.
REST (Representational State Transfer) is the most popular style for web APIs. It's not a strict protocol, but a set of architectural principles. REST APIs use standard HTTP methods like
GETandPOSTand are known for being flexible and scalable.
SOAP (Simple Object Access Protocol) is an older, more rigid protocol that was common before REST. It relies heavily on XML for its message format and has strict rules for communication. While less common for new web services, you'll still find it in many enterprise environments.
GraphQL is a newer query language for APIs developed by Facebook. Its main advantage is efficiency. With GraphQL, the client can request exactly the data it needs, nothing more and nothing less, often in a single API call. This solves the problem of getting too much or too little data, which can happen with REST APIs.
APIs in Action
You interact with APIs every day, even if you don't realize it. They are the invisible engines powering many of the apps and services you use.
When you check the weather on your phone, the app is likely making an API call to a weather service to fetch the latest forecast. When you book a flight on a site like Expedia, it uses APIs from various airlines to pull flight times and prices into one place.
Even simple social logins are powered by APIs. When a website offers to let you "Log in with Google," it's using Google's API to securely verify your identity without you needing to create a new password. The website simply asks Google's API, "Is this person who they say they are?" and gets a yes or no answer.
Ready to check your understanding?
Based on the provided restaurant analogy, what is the primary function of an API?
When you use a travel website to see flights from multiple different airlines at once, what is enabling that website to gather all that information?
APIs are the essential connectors of the digital world, allowing different systems to work together seamlessly. By providing a common language and set of rules, they enable the rich, integrated experiences we've come to expect from modern software.