AlgoMaster Logo

What's an API?

High Priority10 min readUpdated September 19, 2026
AI Mock Interview

Practice this topic in a realistic system design interview

Listen to this chapter
Unlock Audio

What's an API?

Almost every system you design is made of pieces of software that need to talk to each other. APIs are how they do it.

This lesson covers what an API actually is, how API requests and responses work, and why APIs are such an important building block in system design.

1. What Is an API?

An API, or Application Programming Interface, defines how one piece of software can communicate with another.

You use APIs all the time, even if you never see them.

When you open a food delivery app, the app might call one API to fetch nearby restaurants, another to place your order, another to process the payment, and another to track the delivery.

The mobile app doesn't need to know how any of those systems work internally. It only needs to know how to communicate with them.

That's the basic idea behind an API.

2. The API Contract

At a high level, an API is a contract that defines how two pieces of software communicate with each other.

It tells the client:

  • what operations are available,
  • what data it needs to send,
  • and what kind of response it can expect back.

For example, imagine a mobile app that needs information about a user. The app might send a request like this:

And the server might return a JSON object with an id of 123 and a name of Alice:

The mobile app doesn't need to know how the server finds that user. The data might come from a database, a cache, or even another service.

All the client needs to understand is the API contract: send this request, and expect a response in this format.

3. Clients and Servers

Most APIs involve two sides: a client and a server.

The client is the application that sends a request. This could be a web app, a mobile app, a command-line tool, or even another backend service.

The server receives that request, performs some work, and sends back a response.

4. Anatomy of an API Request

For an HTTP API, a request usually has a few important parts.

Suppose we want to create a new order. The request might look like this:

It includes an Authorization header containing a bearer token, a Content-Type header set to application/json, and a JSON body for restaurant 42, with item 101 and a quantity of two.

HTTP Method

The first part is the HTTP method. Here, POST tells the server that we want to create something or perform an action.

Endpoint

Next is the endpoint, in this case /orders, which identifies the resource or operation we want to access.

Headers

Then we have headers. Headers carry additional information about the request, such as:

  • authentication credentials (Authorization: Bearer <token>),
  • the format of the data being sent (Content-Type: application/json),
  • or the type of response the client expects (Accept: application/json).

Query Parameters

A request can also include query parameters. These are values added to the URL to provide extra input:

Here, category and limit narrow down which products come back.

Request Body

And finally, methods like POST, PUT, and PATCH often include a request body, which contains the actual data we want to send to the server. In the order request above, the body is the JSON object with the restaurant and the items.

So at a high level, an HTTP API request can include five main pieces:

PartPurposeExample
HTTP methodThe action the client wantsPOST
EndpointThe resource or operation to access/orders
HeadersExtra information about the requestAuthorization, Content-Type, Accept
Query parametersExtra input added to the URL?category=books&limit=20
Request bodyThe actual data being sentJSON order

Not every request uses all of them, but these are the core building blocks you'll see again and again.

5. API Endpoints

An API endpoint is a specific URL that a client can call to interact with a resource or perform an operation.

For example, a user service might expose endpoints like these:

EndpointWhat it means
GET /users/123Fetch user 123
POST /usersCreate a new user
PATCH /users/123Update part of user 123
DELETE /users/123Remove that user

The path usually identifies the resource, while the HTTP method tells the server what action the client wants to perform. Three of these endpoints share the same path, /users/123. The method is what makes them different operations.

You can think of endpoints as the entry points into a service. A single backend might expose dozens or even hundreds of endpoints, each representing a different capability that clients can use.

6. Anatomy of an API Response

Once the server processes a request, it sends back an API response.

A response usually contains three main parts: a status code, headers, and optionally a response body.

For example, if a request succeeds, the server might return 200 OK, with a Content-Type header set to application/json, and a JSON object with an id of 123 and a name of Alice:

Status Code

The status code tells the client what happened. Here are some common ones:

Status codeMeaning
200 OKThe request succeeded
201 CreatedA resource was created
400 Bad RequestThe request was invalid
401 UnauthorizedAuthentication is required
404 Not FoundThe resource was not found
500 Internal Server ErrorSomething went wrong on the server

Codes in the 2xx range mean the request worked. Codes in the 4xx range mean the client sent something the server could not accept, and codes in the 5xx range mean the server failed.

Headers

The headers provide additional metadata about the response, such as the content type (Content-Type) or caching information (Cache-Control).

Response Body

And the response body contains the actual data being returned. It is optional: a successful DELETE, for example, may return a status code with no body at all.

7. APIs Hide Implementation Details

One of the most important benefits of an API is that it hides the internal implementation of a system.

Imagine a client calls:

From the client's point of view, that is just one API request. But behind that endpoint, the server might check a cache, query a database, call another service, or even run a machine learning model before returning the result.

The client does not need to know any of that. It only needs to know the API contract: what request to send and what response to expect.

This creates a clean boundary between the client and the server. The backend team can change the database, add caching, split one service into several services, or completely rewrite the internal logic without affecting the client, as long as the API contract stays the same.

That separation reduces coupling and makes different parts of a system easier to evolve independently.

8. Public, Private, and Partner APIs

APIs can be grouped based on who is allowed to use them.

Public APIs

A public API is exposed to external developers. For example, a payment company might provide an API that lets other businesses accept payments, or a maps provider might expose an API for location and routing data.

Because people outside the company depend on a public API, it needs clear documentation, authentication, rate limits, and a careful plan for changing behavior without breaking callers.

Private APIs

A private API, sometimes called an internal API, is used only inside an organization. For example, an Order Service might call an internal Inventory Service API to check whether a product is available.

Internal does not mean informal. Internal APIs still need owners, timeouts, stable request and response shapes, and clear behavior when something fails.

Partner APIs

Then there are partner APIs, which are exposed only to selected external companies or business partners.

So the main difference is not how the API works technically, but who is allowed to access it.

In large systems, most APIs are often internal, because services constantly need to communicate with other services behind the scenes.

9. What Makes a Good API

A good API should be easy to understand, predictable, and difficult to misuse.

  • Consistent naming and structure. Once a developer understands one part of the API, the rest feels familiar.
  • Clear errors. When something goes wrong, the API says what happened, rather than leaving the client guessing.
  • Careful changes. APIs often evolve over time. Breaking an existing API can affect every client that depends on it, so backward compatibility becomes important.

We'll cover many of these topics later in the course, but the main idea is that a good API is not just functional. It should provide a clear and reliable contract that clients can safely depend on.

In the next lesson, we'll look at the different types of APIs you're likely to encounter in real-world applications and when each one is used.

Quiz

What is an API? Quiz

10 quizzes