What is an API?

You hear the term "API" in meetings, documentation, and developer conversations. What is an API? Why does it matter to you?

What API Stands For

API stands for Application Programming Interface.

Application: Software that performs a task.
Programming: Writing code to make computers work.
Interface: A boundary where two systems meet and communicate.

An API lets one piece of software talk to another in a structured, predictable way.

How APIs Work

You send a request. You get a response. The other system's internals stay hidden from you.

Say you build an app that displays weather data. You have two options. Set up weather stations across the globe, hire meteorologists, and process satellite data yourself. Or ask someone who already does that work.

Here is what calling a weather API looks like:

// Request weather data for San Francisco
const response = await fetch('https://api.weather.example/v1/current?city=San+Francisco');
const weather = await response.json();

console.log(weather);
// { temperature: 68, conditions: "sunny", humidity: 45 }

One request. One response. Your app now knows the weather.

The API Contract

APIs work because they are predictable. When you call an API, you follow an agreed-upon contract. The documentation tells you:

What requests you make. What format your requests use. What you get back. What happens when things fail.

This contract lets you build with confidence. The API provider honors the contract. Your code keeps working. They rewrite their internals. Your code still works.

Types of APIs

REST APIs are most common. They use standard HTTP methods (GET, POST, PUT, DELETE) and return JSON data.

# Get a user
curl https://api.example.com/users/123

# Create a user
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "alice@example.com"}'

GraphQL APIs let you request the exact data you need. You send a query describing your requirements.

query {
user(id: "123") {
name
email
posts {
title
publishedAt
}
}
}

WebSocket APIs maintain persistent connections for real-time communication. Chat apps, live scores, and stock tickers use them.

Why Documentation Matters

An undocumented API is useless. You have a well-designed API. Developers cannot figure out how to use it. They leave. They find an alternative with better docs.

Good API documentation answers three questions:

How do I authenticate? What endpoints exist? Where are the working examples?

The best documentation explains why certain design decisions were made. It warns about common pitfalls. It provides copy-paste examples that work.

Authentication

Most APIs require authentication. You prove who you are. You prove what you are allowed to do.

API keys are the most common approach. A unique string identifies your application:

const response = await fetch('https://api.example.com/data', {
headers: {
'Authorization': 'Bearer your-api-key-here'
}
});

OAuth lets users grant your application limited access to their accounts. They never share their passwords. This is how "Sign in with Google" works.

Error Handling

APIs fail. Networks fail. Servers crash. Rate limits get exceeded. Your code handles these situations.

HTTP status codes tell you what happened:

200 OK - Everything worked
400 Bad Request - You sent something invalid
401 Unauthorized - Your credentials are missing or wrong
404 Not Found - The resource does not exist
429 Too Many Requests - Slow down
500 Server Error - Something broke on their end

Good error handling matters. Your app breaks mysteriously, or your app tells users "Weather data is temporarily unavailable. Please try again."

Start Building

APIs are everywhere. They connect the services you use daily. Every time you check the weather, send a payment, or post to social media, APIs work behind the scenes.

The best way to understand APIs is to use them. Pick a public API. Build something small. Make a request. Parse the response. Handle an error.

An API is a conversation between computers. Now you know how to join in.