HTTP architecture / interfaces

REST Web Services: What a REST API Is and How It Works

REST (Representational State Transfer) is an architectural style for distributed hypermedia systems, not a data format and not a protocol. A REST API applies that style over HTTP: resources have addresses, clients exchange representations, and every request carries its own context. Returning JSON from an HTTP endpoint does not make it RESTful.

Published
ScopeREST and HTTP
Constraints6 (5 required, 1 optional)
Interface rules4
Safe methods4
Creation / no body201 / 204

One GET request through the REST rules

  1. A client asks a server for one resource: GET /orders/42, with an Accept header.

    Fielding adds the client-server style first (5.1.2), which separates the party asking from the party holding the data. The client sends one request, GET /orders/42, and names the media type it can read, application/json, in the Accept header. The server holds the resource and decides the response. Every later step follows this same message across the wire.

  2. The request carries everything needed; the server relies on 0 stored session entries.

    Fielding's stateless rule (5.1.3) says a request must contain all of the information necessary to understand it and cannot take advantage of any stored context on the server. The target, Host and Accept are enough, so no session cookie is a condition. Sending a Cookie changes 0 lines of the response. The orders themselves stay on the server: the rule concerns session context, not resources.

  3. A fresh stored response answers the second GET; remove freshness and the origin is asked again.

    A response is fresh when it can be reused without validation (RFC 9111). This one says Cache-Control: max-age=60, so a second GET 20 seconds later is answered by the cache with Age: 20, and the origin counts 1 request. With Cache-Control: no-store the rule is gone: a cache must not reuse the response, and the same two calls reach the origin 2 times.

  4. The URI names the resource; the Accept header picks JSON or XML as its representation.

    Fielding's uniform interface has four parts (5.1.5): identification of resources, manipulation through representations, self-descriptive messages and hypermedia as the engine of application state. /orders/42 stays the same while Accept: application/xml selects another representation, proactive negotiation in RFC 9110 terms (12.1), and Content-Type states the result. Vary: Accept keeps the two apart in the cache, so this GET reaches the origin. Hypermedia is not part of this exchange.

  5. Each component "cannot 'see' beyond the immediate layer": the client addresses only the next hop.

    Fielding's layered system (5.1.6) constrains components so that each one cannot "see" beyond the immediate layer with which it interacts. The same GET now passes a cache and a gateway on 3 hops before the origin answers, yet the client opens a connection to the first hop alone. Compared with a direct call on a cache miss, the response differs in 0 lines.

  6. Status and headers report the result: 200 for the read, 201 with Location for a new order.

    The status line tells the client what happened before it reads a body. GET /orders/42 returns 200 with the representation. POST /orders creates a resource under a URI the server chose, so it returns 201 with Location: /orders/43 (RFC 9110, 9.3.3). DELETE /orders is not offered on this collection, so the server answers 405 and must list what is allowed: Allow: GET, HEAD, POST (15.5.6).

  7. 5 rules, 5 traces on the wire; the layered rule's trace is 0 changed lines.

    Client-server shows in the request line and Host. The stateless rule shows in the missing Cookie, the cache in Cache-Control and Age, the uniform interface in Accept, Content-Type and Vary, the layered system in 0 changed lines. Code on demand, Fielding's sixth constraint, is optional (5.1.7) and unused here. Status lines and headers match a small HTTP test server, recorded with curl, character for character.

client
cache
gateway
origin

Client-server

A client asks a server for one resource: GET /orders/42, with an Accept header.

Sources: Fielding, dissertation, chapter 5, RFC 9110, RFC 9111.

What does REST stand for, and what is a REST API?

REST stands for Representational State Transfer. Roy Thomas Fielding described it in his doctoral dissertation, “Architectural Styles and the Design of Network-based Software Architectures”, written at the University of California, Irvine, in 2000. Chapter 5 presents REST as an architectural style for distributed hypermedia systems.

Fielding introduces the idea with a design question about the Web itself. In section 5.1 he writes that “the design rationale behind the Web architecture can be described by an architectural style”. The style is that description, written as a handful of constraints that can be named and tested.

The word style carries the meaning. REST is not a file format, not a protocol and not a product. It is a set of constraints on how the parts of a networked system talk to each other, and a design is RESTful to the degree that it accepts them.

In daily use, a REST API is an interface that applies this style over HTTP. Things the system knows about have addresses, clients ask for and send representations of those things, and every request explains itself. The phrase web service points the same way: a service that programs reach over HTTP. Plenty of services use HTTP verbs and return JSON and still ignore several of the constraints below, so the label deserves a check rather than trust.

What are the REST constraints and principles?

Fielding’s chapter 5 builds REST up from a list of constraints: client-server (section 5.1.2), stateless (5.1.3), cache (5.1.4), uniform interface (5.1.5) and layered system (5.1.6). Code on demand (5.1.7) is described as “only an optional constraint within REST”. That makes five required constraints and one optional one.

ConstraintEffectWhat shows on the wire
Client-serverUser interface and data storage are separate concerns, so each side can change on its own while the interface holdsA request from the client, a response from the server
StatelessEach request carries what is needed to understand itCredentials and parameters travel with every request
CacheA response says whether it may be reusedCache-Control and related headers
Uniform interfaceAll resources are handled in the same generic wayURI, method, media type, status code
Layered systemIntermediaries can sit between client and serverA proxy or gateway that forwards the request
Code on demand (optional)The server may send code that extends the clientA script delivered in a response

Each rule trades something for something. Separating client and server lets a mobile app, a browser and a script share one service, and lets the service change its internals without breaking them, as long as the interface keeps its promises. Statelessness makes every request independent, so no particular server has to remember the earlier ones. Cache rules cost the server a little care in labelling responses and give back lower latency and less work. Wrong labels do harm, though: a response that should be private but may be reused by a shared cache exposes data, and a response cached too long serves stale state. The layered system allows gateways, proxies and load balancers to be added without the client being rewritten. Code on demand is the odd one out, and the dissertation itself treats it as optional.

The uniform interface is the one with parts of its own. Fielding names four: identification of resources, manipulation of resources through representations, self-descriptive messages and hypermedia as the engine of application state. The first two are covered in the next section. Self-descriptive messages are the reason a response names its media type, and hypermedia means that a response tells the client what it can do next.

Stateless is the constraint most often misread. According to section 5.1.3, each request “must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server”. Read plainly, this does not say that the server stores nothing. A server can keep thousands of orders in a database. What it cannot do is depend on a hidden conversation, such as “this client logged in three calls ago”, to make sense of the next call. The conversation state lives with the client and is sent along each time.

What is a resource, and what is a representation?

Fielding defines a resource as “a conceptual mapping to a set of entities” (section 5.2.1.1). It is the thing behind an address, not a row in a table or an object in a program. Order 42 can be one resource even if its data is spread over four tables. HTTP uses the same word: RFC 9110 calls the target of a request a resource, and says that most resources are identified by a URI.

A client never touches the resource itself. It receives or sends a representation, a snapshot of the resource’s state in some format such as JSON, XML or HTML. The media type in the headers tells the receiver how to read the bytes. One resource can offer several representations:

Request headerRepresentation returned
Accept: application/json{"id": 42, "status": "shipped"}
Accept: application/xml<order><id>42</id><status>shipped</status></order>

Separating the two ideas has a practical payoff. A resource keeps its address while the formats offered for it grow or change. A client written against the JSON representation of order 42 keeps working when an XML representation appears next to it, because the address and the meaning of the order did not move.

Both rows describe the same order. Which format fits a given job is a separate question, taken up in XML vs JSON.

Addresses follow from this idea. Because the HTTP method already carries the action, resource URIs usually name things, such as /orders/42, rather than actions, such as /getOrder. That is common design advice and not a rule of the dissertation. Where a domain really contains a process, such as a payment run, modelling the process itself as a resource is a reasonable way out.

What does a REST API example look like?

A short order service shows the pieces working together. The host name is a placeholder.

  1. The client creates an order by sending a POST to the collection, /orders, with a representation of the new order in the body.
  2. The server creates it and answers 201 Created. RFC 9110 says a server that created a resource by POST should send 201 with a Location header, and here Location points to /orders/42.
  3. The client reads the order with GET /orders/42. The answer is 200 OK with a representation in the body.
  4. To change it, the client sends PUT to the same address with the complete new state. The server answers 200 or 204.
  5. To remove it, the client sends DELETE. A 204 No Content response confirms success without a body.
POST /orders HTTP/1.1
Host: api.example.com
Content-Type: application/json
Accept: application/json

{"item": "notebook", "quantity": 2}
HTTP/1.1 201 Created
Location: /orders/42
Content-Type: application/json
ETag: "order-42-v1"

{"id": 42, "item": "notebook", "quantity": 2}

Steps four and five show why the choice of method matters. PUT names the address and supplies the whole new state, so sending it twice leaves the order as it was after the first call. DELETE behaves the same way: once the order is gone, a repeat has nothing further to remove. POST to the collection is different, because each call asks the server to make something new.

Every line has a job. The method and URI say what is addressed and what should happen, the media types say how to read the body, the status code reports the outcome, and Location gives the client an address it can use without guessing.

What is the difference between HTTP and a REST API?

RFC 9110 begins by calling HTTP “a stateless application-level protocol for distributed, collaborative, hypertext information systems”. A protocol fixes message formats, methods and status codes. REST fixes none of those. It is a set of constraints that a design can satisfy while using a protocol such as HTTP.

HTTPREST
KindProtocolArchitectural style
Described inRFC 9110Fielding’s dissertation, chapter 5
Concerned withMethods, status codes, headers, message framingConstraints such as stateless interaction, cache and uniform interface

An HTTP API can break the style without breaking the protocol. A single endpoint that accepts every action as a POST with a command in the body is valid HTTP. It also gives up the uniform interface, because the meaning of each call is hidden in the payload.

The reverse also holds: following the style does not require every detail of HTTP to be used. What the constraints ask for is visible in how the interface is shaped. Does each address identify one thing? Does the method say what is wanted? Does the response say how to read it and whether it may be reused? Those questions can be put to any interface, and the answers say more about its design than the transport it happens to use.

A few neighbouring terms are worth separating. An API is any interface a program can call. A web API is one reached over the web. A REST API is a web API designed in the REST style. SOAP, a messaging protocol with its own envelope, is a different design again; SOAP vs REST compares the two with the same request.

What are REST API status codes, and when does each apply?

Status codes group by their first digit. 2xx means the request succeeded, and 4xx means the request was at fault. The exact codes carry more than the class, and a client can act on them without parsing the body. Forcing every outcome into 200 throws that information away.

CodeMeaningWhen it fits
200 OKThe request succeededA read, or a change that returns the new state
201 CreatedA new resource existsAfter POST or PUT created something; send a Location header
204 No ContentSuccess, nothing to send backA change or removal without a body
405 Method Not AllowedThe resource does not support that methodDELETE on a read-only resource; the response lists the allowed methods in an Allow header
409 ConflictThe request clashes with the current stateA PUT whose content contradicts the resource
415 Unsupported Media TypeThe server cannot read that formatA body in a format the resource does not accept

Two details deserve attention. A 201 belongs with a Location header, because the client learns the address of the new resource from it. A 405 belongs with an Allow header, which RFC 9110 requires, so the client learns what it may do instead. Codes without those headers leave the client with a result and no next step.

Errors need the same care as successes. A stable, machine-readable error structure, the same on every operation, lets clients handle failures without guessing from text. How PUT and POST differ in the codes they return is worked through in PUT vs POST.

Is a RESTful API different from a REST API?

Mostly the words are interchangeable. This is an observation about usage, not a rule from a standard: people say REST API and RESTful API for the same kind of HTTP interface. The ending -ful only adds a claim, namely that the design follows the style.

The difference starts to matter when someone tests that claim. Fielding counts hypermedia as the engine of application state among the four uniform-interface constraints (section 5.1.5). Whoever asks whether a given API is RESTful therefore has to decide how strictly that list is read, and an API with resources and methods but no links from one response to the next has not met all four.

Which methods are safe and idempotent in a REST API?

RFC 9110 calls GET, HEAD, OPTIONS and TRACE safe. It defines a method as idempotent when the intended effect of several identical requests equals the effect of one. PUT, DELETE and all safe methods qualify. POST is registered as neither safe nor idempotent. The word intended matters: a server may still log every request, and the rule describes the effect the method asks for.

MethodSafeIdempotent
GETYesYes
HEADYesYes
OPTIONSYesYes
TRACEYesYes
PUTNoYes
DELETENoYes
POSTNoNo

Safe and idempotent are statements about the method as defined, and they bind implementers. A service that changes data on a GET breaks what clients and caches assume about that method. A service that makes PUT append instead of replace breaks what every retrying client assumes.

The practical consequence appears after a failure. If a connection drops before the response arrives, a client may repeat an idempotent request without knowing whether the first one went through. Repeating a POST can create a second order. PUT vs POST follows exactly that case step by step.

How do I design and review a REST API? A checklist

The list below works as a review sheet. Each point can be checked by reading requests and responses, and a failed point usually names its own fix.

  1. URIs identify stable resource concepts rather than actions.
  2. HTTP methods match their defined safety and idempotency.
  3. Status codes distinguish meaningful outcomes.
  4. Representations declare precise media types.
  5. Cache rules are explicit and safe for the data involved.
  6. Conditional requests are supported where concurrent edits matter.
  7. Errors have a stable, machine-readable structure.
  8. The OpenAPI description matches what the service really does.
  9. Payload schemas declare their versions and dialects.
  10. Conversions to agent tools keep authentication and side-effect boundaries intact.

Used in practice, the list works best on real traffic: take five recorded requests and walk each through the ten points. Items three and seven are easy to test this way, because the status code and the error body are visible in every recorded response. Item eight compares the written contract with observed behaviour, and any difference there is a defect in one of the two.

Security sits beside the list, not inside it. OWASP’s REST Security Cheat Sheet covers topics such as HTTPS, access control, JWT, API keys, input validation and error handling, and each deserves its own review.

Which standards describe REST APIs and their contracts?

REST is described in Fielding’s dissertation. HTTP is specified in RFC 9110, with caching in RFC 9111.

A contract is a separate matter. OpenAPI describes the operations of an HTTP API, with their parameters, payload schemas, responses and security requirements. A valid OpenAPI document shows that an API is described, not that it follows REST. In OpenAPI the Schema Object is by default a superset of JSON Schema Draft 2020-12, and the description should name the OpenAPI version it uses. The latest published version is 3.2.1, from September 2026. Representations in XML can be described with XML Schema (XSD), a W3C language for defining a class of XML documents.

The three pieces answer different questions. Fielding’s dissertation says what the style is, RFC 9110 says how HTTP messages behave, and an OpenAPI description says what one particular service offers. Mixing them up leads to arguments in which one side quotes a style rule and the other a message format.

One more use has appeared around OpenAPI descriptions: turning operations into tools that software agents can call. An operation is not automatically a good tool. Tool descriptions have to help a model choose between operations, inputs should be bounded and described, output should be predictable, and calls that change state should keep truthful approval and risk semantics. The OpenAPI-to-MCP Readiness Analyzer checks these signals in a JSON-formatted OpenAPI description and produces a draft tool definition for review.

FAQ

Frequently asked questions

01What does REST API stand for?

REST stands for Representational State Transfer, and API for application programming interface. A REST API is an interface that applies the REST architectural style, which Roy Fielding described in his 2000 dissertation, over HTTP.

02What is a REST API example?

A client sends GET /orders/42 and the server answers 200 OK with a representation of order 42, for example as JSON. Creating an order works the same way: a POST to /orders is answered with 201 Created and a Location header that names the new resource.

03What is the difference between HTTP and REST API?

HTTP is a protocol with methods, status codes and headers. REST is an architectural style that a design can follow while using HTTP, and an HTTP API can ignore it completely.

04What are REST API status codes?

They are the HTTP status codes a REST API uses to report the outcome of a request: 2xx for success, 4xx when the request is at fault. Typical ones are 200 for a normal read, 201 after creation, 204 for success without a body and 405 when the method is not allowed on that resource.

05What is a RESTful API vs REST API?

In everyday use the two terms name the same thing, an HTTP interface built in the REST style. RESTful stresses the claim to follow the style, and the claim can be tested against the constraints.

06What is idempotency in a REST API?

A method is idempotent when several identical requests have the same intended effect as one. RFC 9110 lists PUT, DELETE and the safe methods as idempotent, which is why a client may repeat them after a dropped connection.

07What is REST in programming?

It is a way of structuring the interface between programs that talk over a network. Instead of calling named procedures, a client reads and changes resources that have addresses, using a small fixed set of operations.

08What is meant by RESTful API?

An API whose design follows the REST constraints: client and server are separate, requests are stateless, responses can be cached, the interface is uniform and layers are allowed. The details of each constraint are covered above.