Your contact form sends leads to your email marketing tool. Your online store shows live shipping rates. Your website displays a map, a weather widget, or the latest reviews from another site. None of that happens by magic. In each case, one piece of software is asking another for something, using an agreed set of rules. That set of rules is an API.
If you run a website, you will hear the term constantly, from plugin settings screens to developer quotes. This guide explains what an API is in plain English, how it works, and what you need to know to use APIs safely.
The short definition
API stands for Application Programming Interface. It is a defined way for one program to request data or actions from another program, without needing to know how that other program works inside.
The restaurant analogy
You sit at a table (your website). The kitchen (another company's system) can make food, but you can't walk in and cook. Instead, you look at a menu (the API documentation) that lists what you can order and how. You give your order to the waiter (the API), who takes it to the kitchen and brings back your meal (the response). You don't need to know the kitchen's recipes, and the kitchen doesn't let strangers wander around. Everyone gets what they need through a controlled channel.
How a web API request works
Most APIs you'll meet as a website owner are web APIs that work over HTTP, the same protocol your browser uses. A request has a few parts:
- Endpoint: the URL you send the request to, such as
https://api.example.com/v1/orders. - Method: what you want to do. The common ones are:
GETto read dataPOSTto create somethingPUTorPATCHto updateDELETEto remove- Headers: extra information, often including authentication.
- Body: the data you're sending, for requests that create or update.
The server sends back a response with a status code and usually some data. Status codes you will see:
200 OK: success.201 Created: something new was created.400 Bad Request: something was wrong with what you sent.401 Unauthorizedor403 Forbidden: authentication failed or you lack permission.404 Not Found: the endpoint or item doesn't exist.429 Too Many Requests: you've hit a rate limit.500range: something broke on the provider's side.
JSON: the language of most APIs
Most modern APIs exchange data in JSON (JavaScript Object Notation), a text format that's readable by humans and easy for programs to parse:
{
"id": 1042,
"customer": "Jane Smith",
"total": 49.95,
"status": "shipped",
"items": ["T-shirt", "Mug"]
}
Curly braces hold named fields, square brackets hold lists. Once you can read that, you can make sense of most API documentation examples.
REST, GraphQL, and other styles
You'll see a few names for API styles:
- REST is the most common. It organizes things as resources at URLs (
/customers,/customers/42/orders) and uses the HTTP methods above. - GraphQL uses a single endpoint where the client describes exactly which fields it wants. It is popular with apps that need flexible data.
- SOAP is an older, XML-based style still found in some enterprise and financial systems.
For most website integrations, you'll be dealing with REST and JSON.
Try one yourself
You can make an API request from your own computer with curl, a command-line tool included in macOS, Linux, and recent versions of Windows. For example, GitHub's public API returns information about a public repository without any login:
curl https://api.github.com/repos/wordpress/wordpress
You'll get a block of JSON back. That's an API response, the same kind of thing your website's plugins and apps receive behind the scenes. Tools like Postman or Insomnia offer a friendlier visual way to explore APIs.
API keys and authentication
Most APIs need to know who's calling, both for security and to track usage. Common methods:
- API keys: a long secret string you include with each request, usually in a header. You generate it in the provider's dashboard.
- OAuth: the "Sign in with..." flow where you approve an app's access to your account without handing over your password. It issues tokens that can be limited in scope and revoked.
- Bearer tokens: a token sent in an
Authorizationheader, often obtained through OAuth.
Keep keys secret
An API key is like a password for your account with that service. Some keys can send emails, charge cards, or delete data. Protect them:
- Never paste secret keys into front-end JavaScript or public HTML, where anyone can read them.
- Don't commit them to Git repositories. Store them in environment variables or a
.envfile that stays out of version control. - Give each key the minimum permissions it needs, if the provider allows it.
- Rotate (replace) a key immediately if you think it leaked.
Some services issue publishable keys meant for front-end use and secret keys that must stay on a server. Read the provider's documentation to know which is which.
Webhooks: APIs in reverse
With a normal API call, your site asks for information. A webhook flips that around: the other service calls your site when something happens. For example, a payment provider can notify your site when a payment succeeds, or a form service can send each new submission to a URL you choose.
You give the service a URL on your site, and it sends a POST request there with JSON describing the event. Good practice is to verify webhook signatures (most providers sign their requests) so nobody can send fake events to your endpoint.
Rate limits and reliability
Providers usually cap how many requests you can make in a period. If your site exceeds it, you'll get 429 errors. To stay within limits and keep your site fast:
- Cache responses that don't change often instead of calling the API on every page load.
- Handle errors gracefully, so a slow or failing API doesn't take your whole page down.
- Watch for deprecation notices. APIs change versions, and old versions are eventually retired.
APIs you probably already use
- Payment gateways in your online store.
- Email marketing integrations that add subscribers from your forms.
- Maps and location widgets.
- Social login and social feeds.
- Shipping rate calculators.
- The WordPress REST API, built into WordPress, which lets apps and other sites read and manage your content.
Wrap-up
So, what is an API? It's a menu and a waiter for software: a documented way to ask another system for data or actions. Web APIs send HTTP requests to endpoints, usually exchange JSON, and use API keys or OAuth to know who's asking. Understand those basics, keep your keys secret, and you'll be able to read integration docs, talk confidently with developers, and connect your website to the tools that make it more useful.