API Development 101: When Your Website Needs to Talk to Other Systems
In this article
An API (application programming interface) is the way one piece of software asks another for something. It is a request sent over the web in an agreed format, and a reply in the same format. Your website needs to use one the moment it has to send data to another system, such as a CRM or your accounts package. The same applies when it has to fetch data from one, such as postage rates or a card payment result. It needs to offer one the moment something else needs your data: a mobile app, a customer's own system, or a separate front end.
Those are two different jobs. Almost every business website does the first, usually without the owner knowing. Only platforms need the second. This guide explains how an API works at the level you need to read a quote or a developer's proposal. That means REST and JSON, authentication with keys or OAuth, and rate limits. It also covers the handful of practices that separate an integration that runs for years from one that fails silently at 2am.
What an API actually is
Most APIs you will meet follow a style called REST. Each kind of thing the system holds (a customer, an order, a lead) has an address. The standard web verbs say what you want to do with it: GET to read, POST to create, PUT or PATCH to update, DELETE to remove. The data in both directions is JSON, a plain-text format of names and values that every language can read.
The reply carries a status code:
- 200 or 201 for success.
- 400 for a bad request.
- 401 for missing credentials.
- 403 for forbidden.
- 404 for not found.
- 429 for too many requests.
- 500 when the other side broke.
A request to create a lead looks like this:
POST /api/v1/leads/ HTTP/1.1
Host: example.co.uk
Authorization: Bearer ccw_live_4f9a...
Content-Type: application/json
{"name": "Ada Lovelace", "email": "ada@example.com", "service": "rewire"}
And the reply:
HTTP/1.1 201 Created
Content-Type: application/json
{"id": 1842, "status": "new", "created": "2026-10-16T09:41:00Z"}
That is the whole mechanism. Everything else, from authentication to rate limits, is a rule about who may send that request and how often.
Using someone else's API
This is the common case. When a customer pays on your site, your code never touches the card: it sends an amount to Stripe's API and gets back a success or a decline. When an enquiry form is submitted, your code can POST it to HubSpot or Salesforce so the lead never sits in an inbox.
Postage in the cart, address lookup, exchange rates, transactional email, SMS reminders and accounting entries in Xero all work the same way. Stamp and Bake's shop shows Royal Mail postage in the cart and prices in 22 currencies. That is the kind of feature that depends on outside data being kept current rather than typed in.
The practices that make these integrations reliable are simple and routinely skipped:
- Keep keys in environment variables on the server, never in the code or the repository, and use the provider's test keys on staging.
- Set a timeout on every call. A provider that is slow should not make your checkout hang.
- Retry failures with increasing delays, but only for calls that are safe to repeat; a retried payment without an idempotency key can charge twice.
- Run anything that is not needed for the page to load, such as pushing a lead to a CRM, as a background job. That way a provider outage never shows on your site.
- Log every request and response, with secrets removed, so a dispute about what was sent can be settled from the record.
The payment case has its own rules, covered in integrating payments into an online store securely.
Building your own API
You build an API when something outside your Django codebase needs your data. That might be a mobile app, a customer who wants to pull their records into their own system, a partner who sends you orders, or a reporting tool.
In Django we build it with Django REST Framework, which turns models into JSON through serializers and handles permissions and pagination. It also gives developers a browsable version of the API in the browser for testing. The API gets a version in its address (/api/v1/) from the first day so it can change later without breaking the people using it. Its documentation is generated from the code in the OpenAPI format, so it is never out of date.
On an MVP the API is usually a second-stage item. The first stage proves the product with server-rendered pages. The second exposes the same business logic through endpoints, which is why we keep that logic out of the views from the start. How we build a SaaS MVP in stages explains that order.
Authentication: keys, OAuth and sessions
Every request has to say who is asking, and there are three common ways to do it.
| Method | Who it identifies | How it is sent | When to use it |
|---|---|---|---|
| API key | A system or an account you issued the key to | In an Authorization header on every request | Server-to-server calls, partners, your own mobile app's backend |
| OAuth 2.0 | A user who has granted your app access to their account on another service | A short-lived access token, renewed with a refresh token | Reading a user's Xero, Google or Microsoft data on their behalf |
| Session cookie | A logged-in user of your own site | Automatically by the browser | Your own front end calling your own API |
An API key is a long random secret. Issue one per client, store only a hash of it (as you would a password), show it once, and let the owner revoke and reissue it. Attach scopes so a key that only needs to read orders cannot create them.
OAuth 2.0 is for the case where the data belongs to someone else's user. Your app sends them to Xero to approve access, Xero sends back a code, and your server exchanges it for tokens. Those tokens are stored encrypted and refreshed before they expire. It is more work than a key and the only correct way to act on a user's behalf. JSON Web Tokens are a popular alternative for mobile apps; they work, but they cannot be revoked before they expire, so keep them short-lived.
Rate limits, idempotency and errors
A rate limit is the number of requests a client may make in a period. Every serious API has one, because one misbehaving client can otherwise slow the service for everyone. When the limit is hit the API answers 429 with a Retry-After header, and a well-written client waits that long before trying again. In Django REST Framework the limit is a setting:
REST_FRAMEWORK = {
"DEFAULT_THROTTLE_CLASSES": [
"rest_framework.throttling.UserRateThrottle",
],
"DEFAULT_THROTTLE_RATES": {"user": "600/hour"},
}
Idempotency is the rule that sending the same request twice has the same effect as sending it once. Reads are idempotent by nature. Creates are not, which is a problem when a network fails after the server acted but before the client heard back. The fix is an idempotency key. The client sends a unique value with each create, and the server stores it with the result. A repeat with the same key returns the stored result instead of creating a second record. Stripe's API works this way and so should yours for anything that moves money or sends a message.
Errors should be as consistent as successes: the right status code and a JSON body with a machine-readable code and a human-readable message. "Something went wrong" in a 200 response is the single most common fault we find when we take over an existing integration.
Webhooks: the other direction
An API answers when asked. A webhook is the reverse. The other system calls you when something happens, such as a payment succeeding or an invoice being paid in Xero, so your site does not have to keep asking. Most real integrations use both: your site calls the provider's API to start something, and the provider's webhook tells you when it finished. What webhooks are and how they automate your business covers signatures, retries and the idempotent handlers they need. For updates that have to reach a browser the instant they happen, WebSockets versus HTTP polling is the next read.
What it involves on a build
Using a provider's API is normal business-website work: a form that reaches your CRM, postage in the cart, a booking that lands in a calendar. Offering your own API is platform work and is scoped as such on our web platform builds. It is quoted after a short call and built as a stage once the core product exists. Keys, documentation and rate limits are included because an API without them is a liability. Either way, the integration list belongs in the requirements document before the quote. The workflows most often behind it are described in custom web apps that automate startup workflows.
Questions people ask
What is the difference between an API and a webhook?
With an API, your system asks and the other system answers. With a webhook, the other system tells you when something has happened. APIs pull; webhooks push. Most integrations need both.
Is REST the same as JSON?
No. REST is the style of the API: addresses for things and standard verbs for actions. JSON is the format of the data that travels. Most REST APIs use JSON, but either can exist without the other.
Do I need an API to have a mobile app?
Yes. A mobile app is a front end with no data of its own; every screen is filled by calling your API. If the web app's business logic is already separate from its pages, building that API is a matter of weeks rather than a rewrite.
What is an API key and how should I look after it?
A long random secret that identifies the system making a request. Treat it like a password: keep it on the server in an environment variable, never in code or a spreadsheet, give each system its own, and revoke any that leaks.
Where to start
List every system your business uses that holds data your website also holds, and mark which direction the data should flow. That list is the integration section of a requirements document. It tells a developer which of the two jobs you need: calling other people's APIs, which is routine, or building your own, which is a stage of a platform.