Web / API Series

🔗 What Is a RESTful API? Understanding from HTTP/JSON Basics to Practical Design from a "Top 1%" Perspective

Introduction

This article is part of the Top 1% Series’ full article guide.

Behind the understanding that “an API is something you GET/POST against a URL” lies a “same communication method” that this article digs into in detail — that is, what HTTP, REST, and JSON are actually doing.

Prerequisites

What's the Difference Between a "Protocol" and an "API"?

These are two distinct concepts operating at different layers — an API is built on top of a protocol.

  • A protocol refers to the “rules of procedure and format” that two devices or pieces of software must follow when communicating — the grammar and etiquette of communication itself, so to speak: “requests and responses are exchanged in this order, in this format.” HTTP and TCP are representative examples of protocols — general-purpose rules that don’t depend on any particular piece of software and can be used in common by any combination of client and server.
  • An API refers to the individual window and set of conventions that a piece of software (a server) exposes externally, announcing “here’s what operations you can perform against me.” “GET this URL and you can retrieve user information,” “POST to this URL and you can create a user” — these are conventions specific to that particular service, and differ from the API of any other service.

To use an analogy: a protocol is like “the etiquette of how to make and conduct a phone call” (identify yourself when the other party answers, state your business, and so on), while an API is like “the specific extensions you can reach when you call a particular company” (press this digit for order intake, that digit for returns). The etiquette (the protocol) is shared across companies, but the contents of the extensions (the API) differ from company to company. The accurate way to understand a RESTful API is as the combination of “individual services each exposing their own API (window), following the etiquette laid down by the protocol called HTTP.”

Getting the Big Picture

In a Nutshell

A RESTful API is “a unified set of conversational rules between pieces of software that uses the exact same mechanism as viewing a website (HTTP), specifies the target of an operation via a URL, and expresses what to do using verbs like GET/POST/PUT/DELETE.” Just as opening https://example.com/users/123 in a browser displays the page for user 123, an API expresses an operation by combining a URL like https://api.example.com/users/123 with a verb such as “GET” (view) or “DELETE” (remove).

The Big Picture of Requests and Responses

sequenceDiagram
    participant Client as Client<br/>(browser/script/iDRAC tool, etc.)
    participant Server as Server<br/>(web server/API server)

    Client->>Server: HTTP request<br/>(method + URL + headers + body)
    Note over Client,Server: Example: PATCH /redfish/v1/Systems/System.Embedded.1<br/>Body: {"PowerState": "On"}
    Server-->>Client: HTTP response<br/>(status code + headers + body)
    Note over Client,Server: Example: 200 OK<br/>Body: {"PowerState": "On", ...}

An API sounds complicated, but in reality it’s just “a program performing, on a human’s behalf, the exact same form of communication a browser has with a server.”

Fundamentals, Thoroughly Explained

What Is HTTP?

HTTP (HyperText Transfer Protocol) is a protocol that defines a single round-trip exchange: the client sends a request, and the server returns a response.

Components of a request

ElementContentExample
MethodA verb expressing what you want to doGET, POST, PUT, PATCH, DELETE
URL (path)The location of the target resource/redfish/v1/Systems/System.Embedded.1
HeadersMetadata (authentication info, data format, etc.)Authorization: Basic xxxx, Content-Type: application/json
BodyThe actual data being sent (usually empty for GET){"PowerState": "On"}

Components of a response

ElementContent
Status codeA 3-digit number expressing the result of the request (discussed below)
HeadersMetadata (data format, cache directives, etc.)
BodyThe returned data itself (typically in JSON format)

Reading Status Codes

RangeMeaningRepresentative examples
2xxSuccess200 OK (success), 201 Created (creation succeeded), 204 No Content (success but no body)
3xxRedirection301 Moved Permanently (a permanent new location exists)
4xxClient-side issue400 Bad Request (the request itself is malformed), 401 Unauthorized (no or invalid credentials), 403 Forbidden (authenticated, but insufficient permission), 404 Not Found (the resource doesn’t exist), 429 Too Many Requests (too many requests)
5xxServer-side issue500 Internal Server Error (an internal server error), 503 Service Unavailable (temporarily unable to process)

404 Not Found is classified as a “client-side issue” because it stems from the request itself — from the specification of a path or ID that doesn’t exist. That said, it’s worth noting that this doesn’t necessarily mean “the client is at fault, in the sense of a bug or improper operation.” For example, consider the case where “a resource that existed just moments ago was deleted by someone else, and access happened right after” — this too returns a 404, but the cause here isn’t really a client implementation mistake — it’s that “the information the client was holding (the premise that the resource still existed) became stale due to a state change on the server side.” Either way, the accurate way to think about it is that “the server-side processing completed normally; the requested resource simply doesn’t exist in the server’s current state” — and from a response-classification standpoint, this consistently falls under 4xx (client-caused).

HTTPS (HTTP + TLS)

HTTPS is HTTP communication with its content encrypted using a mechanism called TLS (Transport Layer Security). It’s a mechanism to prevent eavesdropping and tampering even if an attacker gets in the middle of the communication path, and it’s an essential prerequisite for API communication that exchanges authentication credentials or configuration-changing commands.

What TLS Actually Does (Inside the Handshake)

What TLS does for HTTP communication breaks down broadly into two things: “confirming there’s no impersonation (authentication)” and “establishing a path that can’t be eavesdropped on or tampered with (encryption).” The preparation for achieving both of these happens in the brief initial moment when communication begins — the TLS handshake.

sequenceDiagram
    participant C as Client (browser, etc.)
    participant S as Server

    C->>S: ClientHello (list of supported cipher suites, random value, etc.)
    S-->>C: ServerHello (chosen cipher suite, server certificate, random value)
    Note over C: Verify the certificate (is the CA's signature valid? is it within<br/>its validity period? does the domain name match?)
    C->>S: Key exchange information (encrypted with the public key in the certificate)
    Note over C,S: Both sides derive the same "symmetric key"
    Note over C,S: All subsequent communication is exchanged encrypted with AES etc. via the symmetric key
  1. Authentication via the server certificate: The server presents the client with a “certificate” issued by a Certificate Authority (CA) — the server’s public key together with a digital signature by which the CA guarantees that domain name. The client verifies whether this certificate was signed by a trusted CA built into the browser/OS, whether it’s within its validity period, and whether the domain name it’s connecting to matches what’s recorded in the certificate. If this verification fails, a warning such as “this connection is not private” is displayed.
  2. Key exchange: Once certificate verification passes, the client and server use “public-key cryptography” (a scheme that exploits the one-directional property that only the server holding the corresponding private key can decrypt something encrypted with the public key in the certificate) to securely share a symmetric key (a key for symmetric-key cryptography, known only to both parties) that will be used to encrypt all subsequent communication. Public-key cryptography is secure but computationally expensive, so it isn’t used for the actual exchange of data — it’s used solely to securely hand over the symmetric key at the start.
  3. Encrypted communication via the symmetric key: All subsequent actual HTTP requests and responses are exchanged encrypted using symmetric-key cryptography (such as AES, which processes faster than public-key cryptography) with this symmetric key.

Because of this sequence, even if an attacker inserts themselves into the communication path along the way, certificate verification lets any “impersonation” be detected, and even if the communication data is intercepted, it appears as nothing but ciphertext to a third party who doesn’t know the symmetric key — providing double protection.

If you want to go deeper into public-key cryptography itself — why having just two keys is enough to make this secure — plus certificates, CSRs, and how certificate chain verification actually works, Understanding PKI and Digital Certificates from a “Top 1%” Perspective covers it systematically.

What Is REST? (Design Philosophy)

REST stands for “REpresentational State Transfer,” a Web API design style proposed in Roy Fielding’s 2000 doctoral dissertation. Its representative principles are as follows.

PrincipleContent
Client/server separationSeparates the concerns of UI and data management, so each can evolve independently of the other
StatelessThe server doesn’t retain client state between requests; each request must contain, entirely on its own, all the information needed to process it
CacheabilityMakes explicit whether a response can be cached, enabling performance optimization
Uniform interfaceUniquely identifies resources via URLs, and unifies operations around a limited set of verbs such as GET/POST/PUT/DELETE
Layered systemThe client doesn’t need to know whether it’s communicating directly with the server, or whether a load balancer or proxy sits in between

“Stateless” is particularly important. It means the server side doesn’t retain, as a session, per-client state such as “whether this client is currently logged in.” As a result, authentication information (such as a token) must be included with every single request (discussed below).

Uniform Interface (the Meaning of HTTP Methods and Idempotency)

MethodMeaningIdempotency (does sending the same request repeatedly produce the same result?)
GETRetrieve a resourceIdempotent (state doesn’t change no matter how many times it’s executed)
POSTCreate a new resourceNon-idempotent (a new resource can be created each time it’s executed)
PUTReplace a resource in its entiretyIdempotent (sending the same content repeatedly produces the same result)
PATCHUpdate only part of a resourceImplementation-dependent (it’s desirable to design it to be idempotent)
DELETEDelete a resourceIdempotent (deleting an already-deleted resource again doesn’t change its state)
"REST" vs. "RESTful," and APIs That Don't Actually Strictly Satisfy REST's Principles

“REST” refers to the design principles themselves described above, while “RESTful” is the adjective describing an API designed in line with those principles. In practice, however, much of what’s called a “RESTful API” out in the world doesn’t strictly satisfy the principles defined in Fielding’s original dissertation (particularly HATEOAS: the principle that a response should include links to the operations that can be taken next). Many implementations only practice the part that says “represent resources via URLs, use HTTP methods appropriately, and exchange data as JSON” — making them “REST-like” APIs in a looser sense. This is rarely treated as a problem in practice, and it’s closer to the truth to say that the term “RESTful API” is used with the loose understanding of roughly “an API that’s JSON over HTTP, with a resource-oriented URL design.”

What Is JSON?

JSON (JavaScript Object Notation) is a notation for representing data as text in the form {"key": "value"}. It can express hierarchical data by combining collections of key-value pairs (objects) with ordered sequences of values (arrays).

{
  "PowerState": "On",
  "Model": "PowerEdge R760",
  "Processors": {
    "Count": 2,
    "Model": "Intel Xeon"
  }
}

JSON is widely used because, compared to XML (once the dominant format for SOAP APIs), its structure is simpler and more readable to humans, it has strong affinity with JavaScript, and parsing support for it is standard across most programming languages.

Authentication in a Stateless World: The Token Mechanism

Because of REST’s “stateless” principle, the server doesn’t remember “this client logged in a moment ago.” As a result, authentication information must be included with every single request. The representative schemes are as follows.

SchemeOverview
Basic authenticationBase64-encodes the username and password and includes them in the Authorization header. Simple, but effectively equivalent to plaintext, so it must always be paired with HTTPS
API keyIncludes a fixed key string issued by the server in a header or query parameter
Bearer token (session token)Issues a temporary token during a login-like process, then includes it in the Authorization: Bearer <token> header on subsequent requests. iDRAC’s Redfish API also adopts this scheme, creating a session on the first call and issuing an X-Auth-Token
OAuth 2.0A mechanism for delegating only a limited set of permissions to a third-party service without ever handing over the user’s own password. Widely used in large-scale API ecosystems
A Closer Look at How OAuth 2.0 Works (the Authorization Code Flow)

OAuth 2.0 involves four parties.

PartyRole
Resource ownerThe actual owner of the data (e.g., you, currently logged into a service)
ClientThe third-party app that wants to access the data on the resource owner’s behalf
Authorization serverThe server that presents the login/consent screen and issues tokens
Resource serverThe API server that actually holds the data (sometimes the same implementation as the authorization server)

The most representative flow, the “authorization code flow,” proceeds as follows.

sequenceDiagram
    participant User as Resource owner (user)
    participant Client as Client (third-party app)
    participant AuthServer as Authorization server
    participant ResServer as Resource server (API)

    Client->>User: Redirect to the authorization server's login/consent screen
    User->>AuthServer: Log in + grant permissions
    AuthServer-->>Client: Return an authorization code (a temporary voucher)
    Client->>AuthServer: Send the authorization code + the client's own credentials
    AuthServer-->>Client: Issue an access token (+ refresh token)
    Client->>ResServer: Authorization: Bearer <access token>
    ResServer-->>Client: Return the resource data

The key point is that the client (the third-party app) never receives the user’s password. The user logs in and grants consent directly on the authorization server’s own screen, and all the client ever receives is a voucher (the authorization code) meaning “you may act on behalf of this user, within this scope of permission” and the access token subsequently issued in exchange for it. Access tokens are typically given a short validity period, and it’s a common design to pair them with a long-lived refresh token, so they can be renewed without requiring the user to log in again after they expire.

Let’s walk through a concrete example. Say a calendar app (the client) has a “Connect with Google Calendar” button. Clicking it redirects you not to the calendar app’s own server, but to Google’s login screen (the authorization server). The Google account password you type there is received only by Google’s servers — the calendar app never sees it at all. After logging in, you’re shown a consent screen: “Allow this app to read and write your Google Calendar events?” Click “Allow,” and the calendar app receives an access token via the authorization code flow described above. From then on, the calendar app uses that access token to reach Google Calendar’s API (the resource server), but the Google account password itself is never handed to the calendar app at any point — that’s the real-world payoff. Even if the calendar app’s database were ever breached, all that would leak is a scoped, limited access token — never the actual Google account password.

Redfish as a Real-World Example of a “RESTful API”

With everything covered so far in mind, here’s how iDRAC’s Redfish API can be interpreted.

You should now have a concrete picture of how “remotely operating a server” — something that seems like a special case at first glance — is actually built on the exact same HTTP and JSON framework as viewing a website.

Is an "API server" set up separately from the server providing the actual service?

Up to this point, the term “API server” has been used without much explanation, but in real-world practice, it’s common to deliberately separate “the server whose purpose is providing the service itself (displaying a website, processing an order, and so on)” from “the server whose only job is being the API’s front door.” The component that handles this separation is called an API gateway.

An API gateway’s roles include the following:

  • Accepting requests from clients and forwarding them to the appropriate backend service (microservice) based on the URL or header content
  • Handling authentication and authorization centrally at the gateway, rather than in each individual service
  • Centralizing rate limiting and request logging
  • Aggregating requests to multiple backend services and returning them to the client as a single combined response (a pattern called BFF: Backend For Frontend)

This role closely resembles the reverse proxy covered in Understanding When to Use a Proxy vs. a Firewall from a “Top 1%” Perspective. In fact, many API gateways are internally built on top of reverse proxy functionality. The difference is that a reverse proxy sticks to the generic role of “where to forward an HTTP request,” while an API gateway is a more specialized reverse proxy that additionally handles API-specific concerns: API key validation, request/response format transformation, and aggregating multiple services. Whether to separate out an “API server” depends on the system’s scale and whether there’s one backend service or several. With just one backend service, that service can safely expose its API directly, but once a system is split into multiple microservices, centralizing through an API gateway becomes nearly mandatory in real-world practice.

The View from the Top 1% (What Experts See)

Why Idempotency Matters in Practice

Networks can’t always be trusted — you can send a request and then hit a timeout without ever receiving a response. Idempotency is the criterion for judging “is it okay to send the same request again?” in that situation. PUT and DELETE are idempotent, so they can be safely retried, but POST is non-idempotent, so a naive retry risks creating the same resource twice. When designing large-scale API integrations or retry logic, this distinction around idempotency is the foundation for avoiding accidents.

Consider a concrete scenario: you send a transfer request for 10,000 yen via POST /transfers to a money-transfer API, but it times out before a response comes back. At this point, the client can’t tell which of the following actually happened.

  1. The network dropped before the request reached the server (the transfer was never executed)
  2. The server completed the transfer, but the network dropped before the completion response reached the client (the transfer was already executed)

If you naively send the POST again just because “it might not have arrived,” in scenario 2 the transfer ends up executed twice. This is the concrete meaning of “since POST is non-idempotent, a naive retry is dangerous.” In practice, the client issues a unique idempotency key for each request (an Idempotency-Key header containing something like a UUID), and the server is implemented so that when it receives a request with a key it has already processed, it returns the same result as before rather than processing it as new — giving even an inherently non-idempotent operation like POST a way to be retried safely. This is a design standard adopted by many payment APIs (such as Stripe). For why payment APIs are built around a multi-step state machine like PaymentIntent, and how webhooks are used to detect payment completion, see Understanding Payment APIs from a “Top 1%” Perspective.

How Pagination Works

APIs that handle large numbers of resources (such as a Redfish API returning a list of hundreds of servers) commonly return results split across pages, using query parameters like ?page=2&limit=50, rather than returning everything at once — this is called “pagination.” The key point here is that “the rest of the data” isn’t something the server proactively sends — it’s only returned once the client explicitly requests the next page. Because REST is a stateless mechanism, the server doesn’t remember “this client hasn’t been sent page 2 yet.” The server is simply computing and returning “the data corresponding to page 2” each time, in response to the client’s specific request for ?page=2.

There are two representative implementation approaches for pagination.

ApproachMechanismStrengths/Weaknesses
Offset-basedSpecifies “how many items in, how many items” — e.g. ?page=2&limit=50Simple to implement, and lets you jump directly to a specific page. However, if data is added or removed while retrieving results, the page boundaries can shift, causing the same item to appear twice or be skipped entirely
Cursor-basedSpecifies “how far you got last time” — e.g. ?after=<ID of the last item from before>Resistant to shifting even when data is added or removed, and behaves stably against large amounts of data. However, operations like “jump directly to page N” are difficult

In large-scale environments like a Redfish API listing hundreds of servers, where the underlying data can change constantly (servers being added and decommissioned on a routine basis), the cursor-based approach tends to be preferred in practice.

Rate Limiting

To protect the API server, it’s common to put a “rate limit” on the number of requests within a given time window, returning 429 Too Many Requests when that limit is exceeded. When writing large-scale automation (such as a script that hits the Redfish API in bulk across hundreds of iDRACs), implementing retry/wait logic (backoff) that respects rate limits is essential.

API Versioning

Since API specifications can change in the future, it’s common to include a version number in the URL (such as /v1/), or to specify the version via the Accept header. This is a critically important design consideration in practice, preventing older clients from suddenly breaking when a new API specification is introduced.

Common Misconceptions and Pitfalls

Troubleshooting Perspective

Isolating the Cause When an API Doesn’t Respond as Expected

  1. First check the status code. 4xx primarily points to the request side; 5xx primarily points to the server side.
  2. If 401/403 is returned, suspect an expired authentication token, insufficient permissions, or a typo in a header name.
  3. If 429 is returned, it’s a rate limit being exceeded. Wait a while and retry, or reduce your request frequency.
  4. If a timeout occurs, it could be a network path issue, or heavy processing on the server side (such as retrieving a large volume of data). Use curl with the -v (verbose) option to check exactly where things are stalling, from TCP connection establishment through to receiving the response.

Prevention and Long-Term Countermeasures

Summary

Starting Today

  1. Make a habit of consciously checking the HTTP method and status code of the APIs you work with day to day.
  2. When writing an automation script, be conscious of whether each API call is idempotent, and implement retry logic accordingly, safely.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).