Full Byte Developer.

What is an API?

An API is a contract one program offers so another can use a capability without rewriting the internals.

Published here , updated · 4 sources

An API (Application Programming Interface) is a defined way for one program to use another program's capability without rewriting the internals. MDN describes APIs as constructs that let developers create complex functionality more easily by hiding more complex code behind simpler syntax [1][3]. The surface is a contract: methods, paths, formats, and errors you are allowed to rely on.

Quick start: call a local function as a tiny API

MDN's plug-socket analogy is the clean one: you use an appliance through a plug instead of splicing into the mains [1]. The socket is the contract. You still have to follow its rules (shape of the request, auth, formats). A restaurant-menu picture works the same way for HTTP: you pick from listed dishes (endpoints), the kitchen (server) prepares them, and you get a plate (response). That picture does not mean a human waiter sits in the loop.

A tiny local function with a typed signature is an API even when nothing leaves the machine:

bash
python3 - <<'PY'
def add(a: int, b: int) -> int:
    """Callers only need the signature, not the body."""
    return a + b
print(add(2, 3))
PY

Captured on this host:

text
5

Callers depend on the signature and the return value. They do not need the body. At network scale the same rule holds: depend on the published surface, leave private implementation alone.

Call a public HTTP demo

Browser APIs ship inside the browser (DOM, Fetch). Third-party APIs are not built into the browser; your code reaches them somewhere on the web, such as a maps API [1]. Language libraries expose APIs too.

For a networked example, send a GET request (the HTTP method for reading) to httpbin's /get endpoint (one address the API offers). It returns JSON (text laid out as names and values) that echoes the request. It is a public demo service, so use it to learn the shape of a request, not as something your code depends on [4].

bash
curl -sS "https://httpbin.org/get?demo=fullbyte" | python3 -c 'import sys,json; d=json.load(sys.stdin); print(d["url"]); print(d["args"])'

Captured on this host:

text
https://httpbin.org/get?demo=fullbyte
{'demo': 'fullbyte'}

The same call in Node:

bash
node -e 'fetch("https://httpbin.org/get?demo=node").then(r=>r.json()).then(d=>console.log(d.url,d.args))'

Captured on this host:

text
https://httpbin.org/get?demo=node { demo: 'node' }
API as a contract Your app client code request Published menu paths, methods formats, errors response Service internals You depend on the menu, not the kitchen wiring [1][3] REST is one style of web API rules, not every JSON URL [2]

Your app sends a request into the published menu of paths, methods, formats, and errors. The service answers through that contract while keeping private internals hidden. REST is one style of web API rules, not every JSON URL.

Separate REST from "any HTTP API"

MDN's REST glossary defines REST as architecture constraints for distributed systems. HTTP APIs are often called RESTful in casual speech even when they skip some constraints. Beginners can treat a REST API as an HTTP service you call with ordinary web tools, then learn the stricter constraints later [2].

Do not invent a purity fight in a stand-up. Ask whether the team means "HTTP JSON endpoints" or "we follow REST constraints." Those are different claims. Document the methods, auth, and error shapes your clients may rely on either way.

Versioning and breaking changes

An API contract changes when a field disappears, a type changes, or an auth rule tightens. Clients that treated undocumented fields as stable will break first. For OpenAPI diffs that show which clients break when a field is renamed, see Agent renamed an API field? oasdiff shows which clients break.

When an agent calls an API, it is using tools against that contract. Pair this glossary page with what is an AI agent for the agent side of the same idea.

Auth, rate limits, and errors as part of the menu

A complete contract is more than a happy-path path list. Auth headers, rate-limit responses, and documented error bodies are part of what callers must handle. Ignoring them is how demos work once and production clients retry forever.

httpbin is useful because it echoes the request shape without selling you a product [4]. Replace it with your own stub when you need deterministic fixtures in CI. Never point production traffic at a public echo service.

Local library APIs versus remote web APIs

open() in Python is an API. fetch() in the browser is an API. A company's /v1/orders HTTP route is an API. The transport differs; the shared idea is a published surface with rules. MDN's introduction covers browser and third-party web APIs specifically; the glossary definition is broader [1][3].

Promises and the event loop sit under many browser API calls. If that layer is fuzzy, start with JavaScript promises event loop quick start.

Mistakes that show up in reviews

Calling every JSON-over-HTTP endpoint "REST" without checking constraints [2].

Hard-coding against undocumented response fields that a vendor never promised.

Treating a 200 body that contains "error": true as success because the HTTP status looked fine. Read the contract for where errors live.

Shipping a client that only handles the happy path while production rate-limits return 429.

Expecting library APIs and web APIs to follow identical versioning rules. Language libraries often ship with the runtime; remote APIs often need explicit version negotiation.

Depth: what "contract" means for tests

A contract gives you something to assert in tests. For a local function, assert inputs and outputs. For HTTP, assert status, headers, and body shape against fixtures or a stub. When the server side is a long-running process, the glossary for that role is what is a server. When the server runs on rented infrastructure, pair with what is the cloud.

Contract tests fail when either side drifts. Prefer failing the build on a breaking OpenAPI change over discovering it in production support tickets.

Depth: why menus beat source dumps

Teams sometimes say "just read the source" instead of publishing an API. That works for a two-person repo and collapses when another team or an agent needs a stable surface. The menu is the communication channel: it tells callers what will stay available across releases [1][3].

Publish examples that run. The httpbin and local add demos above are the teaching shape: small, checkable, and honest about scope [4].

Depth: status codes versus application errors

HTTP status codes are part of many web API contracts, but they are not the whole story. Some services return 200 with an error object in the body. Others use 4xx for client mistakes and 5xx for server failures. Your client must follow the published rule for that API, not a generic "non-2xx means fail" heuristic copied from another vendor [1][2].

Idempotency matters for retries. A safe GET can usually be retried. A POST that creates a charge needs an idempotency key or you invent duplicate side effects. Put that rule in the client checklist next to auth.

Document pagination and filtering the same way you document paths. Callers who scrape only the first page silently miss data. Cursor or offset parameters belong on the menu alongside the resource names.

Depth: SDK wrappers still sit on a contract

Language SDKs are convenience layers over the same surface. When the SDK lags a breaking API change, the HTTP contract is still the source of truth. Prefer generated clients from OpenAPI when the vendor publishes a schema, and pin versions so a silent major bump does not land in CI overnight [1][3].

Browse the Dev explainers topic.

Send this to the friend who nods when developers say API but has no idea what it is.

Two solid program cubes facing each other across a thin translucent contract plate with geometric ports, where only matching plugs from the left cube can enter, and the right cube's interior stays hidden behind a frosted plane, with no typography or logos.
An API is a contract: a defined surface, not a rewrite of the other program's internals.

Keep this guide

By Full Byte Developer

Filed under Dev explainers

Questions about this guide

Is every HTTP JSON API RESTful?

No. MDN says people often call HTTP APIs REST even when they skip some REST constraints. Treat REST as a set of design rules, not a synonym for any JSON endpoint.

Are APIs only remote web services?

No. Library and language APIs (for example Python open) are also APIs. Web APIs are the networked subset most people mean in browser work.

Is httpbin a production dependency?

No. It is a public request inspection demo. Use it to learn request shape, not as a service you depend on.

Sources

Next in this stack