A REST API is a way for two software systems to exchange data over the web using plain HTTP requests, where each request names a resource (like a user or an order) and an action (read, create, update, delete). The part most people get wrong is that REST is not a protocol or a standard you install; it is a set of architectural constraints, and an API can call itself REST while breaking several of them.
What REST Actually Means
REST stands for Representational State Transfer. The idea is simple: the server holds resources, the client asks for a representation of one, and the client changes things by sending a new representation back. The word "state transfer" is the key. The client does not hold a live session on the server; each request carries everything the server needs to answer it.
That is why authentication tokens, headers and identifiers travel with every call. The server stays stateless between requests. If a request fails, the client can usually retry it without the server remembering what happened last time.
REST was described as a set of constraints rather than a formal specification. There is no certificate, no compliance test and no governing body. So when a service advertises a REST API, treat that as a design intention, not a guarantee. Read the documentation and check the actual behavior.
The Four Core Constraints
Most of what makes an API feel predictable comes from four constraints. Knowing them helps you judge an API before you write a single line of code.
- Client-server separation. The interface between the two sides is fixed, so each can change independently. The client does not need to know how data is stored.
- Statelessness. Each request stands alone. The server does not keep a session for you between calls, so you send credentials and context every time.
- Cacheability. Responses declare whether they can be cached and for how long. A read that rarely changes can be served from a cache instead of hitting the server.
- Uniform interface. Resources are named consistently, messages describe themselves, and the same small set of actions applies everywhere. This is the constraint most APIs bend.
An optional fifth constraint is a layered system: a client may talk to a gateway or proxy without knowing it. That is how load balancers and authentication layers slot in without changing the client.
Resources and URLs
In REST, a URL names a thing, not an action. Nouns belong in the path; verbs belong in the HTTP method. A collection of orders lives at a path like /orders, and one order lives at /orders/1234. Nested things follow the same pattern: /orders/1234/items is the list of items on that order.
Use plural nouns for collections and keep the path lowercase with hyphens between words. Avoid verbs in the path such as /getOrder; that style belongs to older remote-procedure designs. The method already says what you want to do.
Identifiers should be stable and opaque. A numeric ID or a generated string is fine. Do not build identifiers out of data that can change, such as a customer's email address, because renaming the resource would break every stored link.
Query strings handle filtering, sorting and paging, not identity. /orders?status=open&sort=-created reads as "the open orders, newest first." Keep filters as separate parameters so they combine cleanly.
HTTP Methods and Status Codes
Each method maps to one intent, and using the right one keeps clients and servers in agreement.
- GET reads a resource and must not change anything. It is safe to retry.
- POST creates a new resource in a collection, or triggers an action that does not fit the other methods.
- PUT replaces a resource entirely with what you send. Omitted fields are removed.
- PATCH changes only the fields you include. Use it when you do not want to resend the whole object.
- DELETE removes a resource. A second identical call usually returns not-found.
Status codes carry the outcome. 200 means success with a body, 201 means created, and 204 means success with no body. 400 means the request was malformed, 401 means you are not authenticated, 403 means you are authenticated but not allowed, and 404 means the resource is not there. 409 signals a conflict such as a duplicate, and 422 signals that the request was well-formed but the data failed validation. 500 means the server failed; 503 means it is temporarily unavailable and a retry later may work.
Return the right code and clients can react without parsing your error text. A create that returns 200 instead of 201 forces every client to guess whether the resource now exists.
Statelessness and Authentication
Because the server keeps no session, every request must prove who you are. The common pattern is a token sent in the Authorization header, usually as a bearer token. The client obtains the token once, stores it safely, and attaches it to each call.
Treat tokens like passwords. Send them only over encrypted connections, never put them in a URL where they land in logs and browser history, and give them an expiry. When a token expires, the client requests a new one rather than reusing a stale credential.
Statelessness has a cost: larger requests, because context travels every time. It buys simpler scaling, since any server can answer any request without shared session storage. That trade is usually worth it for public APIs.
Request and Response Bodies
JSON is the usual format, and it is worth following a few conventions. Use consistent field naming, either snake_case or camelCase, and stick to it across the whole API. Send dates in a single standard format such as ISO 8601 so clients in different regions parse them the same way.
Wrap collections in an object rather than returning a bare array. That leaves room to add paging details later without breaking clients. Include a total count and a link to the next page when results are paginated.
For errors, return a body with a stable shape: a code, a human-readable message, and the field that failed when relevant. Clients can then show a useful message and log the code without scraping prose.
Versioning and Paging
APIs change, and clients cannot always update on the same day. Version the API so old clients keep working. Common approaches put the version in the path, such as /v1/orders, or in a header. Pick one and document it.
Never change the meaning of an existing field in place. Add new fields freely, because clients should ignore what they do not recognize. Remove or rename only in a new version, and announce a retirement window so integrators can migrate.
For large collections, page the results. Offset paging with limit and offset is simple but drifts when rows are inserted. Cursor paging, where the response returns a token pointing at the next batch, stays stable under changes. Use cursor paging for feeds and logs.
Checking an API Before You Build
A short review saves hours later. Read the documentation and confirm the base URL, the authentication method and the format of errors. Send one GET request and inspect the response headers for caching and rate-limit information. Try a deliberately bad request and see whether the error body is structured or just prose.
Check how the API behaves when a resource is missing, when a token has expired, and when you send an unexpected field. Those three cases reveal more about quality than a happy-path example. If the answers are inconsistent, budget extra time for defensive code.
Finally, confirm the rate limits and what happens when you exceed them. A 429 response with a retry hint tells you how to back off. Without that, a busy client can hammer a server and get locked out. Build retries with a delay, and never retry a non-idempotent POST blindly.