Technology - Non SAP

REST API Design Principles

Every time your phone app loads data, or two systems talk to each other over the internet, there is very likely a REST API in the middle. REST is the most widely used approach for building web APIs today.

This post covers the principles behind REST — not the code, not a specific framework. The principles. Once you understand them, you can design better APIs, review existing ones more confidently, and understand why things are built the way they are.

What REST is

REST stands for Representational State Transfer. It is an architectural style — a set of constraints — defined by Roy Fielding in his doctoral dissertation in 2000.

It is not a protocol. It is not a standard. It is a set of design decisions that, when followed, produce APIs that are predictable, scalable, and easy to work with.

An API that follows REST principles is called a RESTful API.

💡 REST vs RESTful

REST is the architectural style. RESTful is the term used for APIs that follow those principles in practice. In everyday conversation, people use both interchangeably.

The six constraints Fielding defined

Fielding defined six constraints. An API that satisfies all of them qualifies as truly RESTful.

ConstraintWhat it means in plain English
Client-ServerThe client (who asks) and the server (who responds) are separate. Each can change independently as long as the interface between them stays the same.
StatelessEvery request must contain all the information needed to process it. The server does not store anything about the client between requests.
CacheableResponses must tell the client whether they can be cached or not. Caching reduces load and improves performance.
Uniform InterfaceAll interactions follow the same set of rules — resources are identified by URIs, and standard HTTP methods are used consistently.
Layered SystemThe client does not need to know if it is talking directly to the server or through intermediaries (load balancers, gateways, proxies).
Code on Demand (optional)The server can send executable code to the client — for example, JavaScript. This is the only optional constraint.

In practice, the two constraints that matter most day-to-day are Stateless and Uniform Interface. The others are largely handled by infrastructure.

Resources — the foundation of REST

Everything in REST is a resource. A resource is any piece of information that can be named — a user, an order, a product, a document.

Each resource is identified by a URI (Uniform Resource Identifier). The URI is the address of the resource.

REST API URI examples showing resource-based URL patterns for users and orders

How to name resources well

Resource naming is one of the most impactful design decisions in a REST API. A few rules that hold universally:

RuleCorrectWrong
Use nouns, not verbs/orders/getOrders
Use plural nouns/users/user
Use lowercase with hyphens/order-items/orderItems or /Order_Items
Nest for relationships/users/42/orders/getUserOrders?id=42
Keep it readable/products/shoes/prds/cat3/sh

HTTP methods — what action you are taking

REST uses standard HTTP methods to define what you want to do with a resource. Each method has a specific, well-understood meaning.

MethodActionExample
GETRead a resource — no changes madeGET /users/42 — fetch user 42
POSTCreate a new resourcePOST /users — create a new user
PUTReplace a resource entirelyPUT /users/42 — replace all data for user 42
PATCHUpdate part of a resourcePATCH /users/42 — update only the email of user 42
DELETERemove a resourceDELETE /users/42 — delete user 42

HTTP methods table showing GET, POST, PUT, PATCH and DELETE with descriptions and URI examples

Safe and idempotent methods

Two concepts that come up often in API design — worth understanding clearly.

ConceptMeaningWhich methods
SafeThe request does not change anything on the serverGET
IdempotentMaking the same request multiple times produces the same result as making it onceGET, PUT, DELETE
NeitherEach call may produce a different result or create a new recordPOST, PATCH

Idempotency matters in practice because networks fail. If a client is not sure whether a request was received, it can safely retry a DELETE or PUT without worrying about creating duplicates. It cannot safely retry a POST.

Statelessness — each request stands alone

This is one of the most important principles and the one most often misunderstood.

Stateless means: the server does not remember anything about previous requests. Every request from the client must include everything the server needs to process it — authentication token, user context, parameters, everything.

Stateful (not REST)Stateless (REST)
Server stores your session after loginClient sends an auth token with every request
Server remembers your previous step in a workflowClient sends the current state with each request
Harder to scale — session must live on one serverEasy to scale — any server can handle any request

💡 Sessions vs statelessness

Most REST APIs use tokens (like JWT) for authentication. The client stores the token and sends it with every request. The server validates it without storing any session. This is stateless — the token is the state, and it travels with the request.

HTTP status codes — what happened

A REST API communicates the result of every request using HTTP status codes. Using them correctly is part of the uniform interface.

RangeMeaningCommon examples
2xxSuccess200 OK, 201 Created, 204 No Content
3xxRedirection301 Moved Permanently, 304 Not Modified
4xxClient error — the request was wrong400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests
5xxServer error — the server failed500 Internal Server Error, 503 Service Unavailable

The ones that matter most

CodeWhen to use it
200 OKRequest succeeded — return the data
201 CreatedA POST succeeded and a new resource was created — include the new resource URI in the response
204 No ContentRequest succeeded but there is nothing to return — common for DELETE
400 Bad RequestThe client sent something malformed or missing required fields
401 UnauthorizedNo valid authentication was provided
403 ForbiddenAuthentication is valid but the user does not have permission
404 Not FoundThe resource does not exist
409 ConflictThe request conflicts with current state — e.g. duplicate record
422 UnprocessableRequest is well-formed but fails business validation
429 Too Many RequestsRate limit exceeded
500 Internal Server ErrorSomething went wrong on the server — do not expose internal details

API versioning

APIs evolve. New fields get added, old ones get removed, endpoints get restructured. Versioning is how you make breaking changes without breaking existing clients.

ApproachHow it looksCommon use
URL versioning/v1/users, /v2/usersMost common — simple and visible
Header versioningAccept: application/vnd.api+json;version=2Cleaner URLs, harder to test in a browser
Query parameter/users?version=2Less common, not recommended for public APIs

URL versioning is the most widely used approach. It is visible, easy to document, and easy to test. The SAP OData protocol, for example, uses URL versioning — V2 and V4 are distinct service paths.

📌 When to version

Only version for breaking changes — removing a field, changing a data type, or restructuring a resource. Adding new optional fields or new endpoints does not require a new version.

A few practical principles worth knowing

Use JSON as the default format

JSON is the standard response format for REST APIs today. It is lightweight, human-readable, and supported everywhere. Always set the Content-Type header to application/json.

Design for the consumer

The people calling your API should not need to know how your database is structured. Expose resources that make sense from the consumer’s perspective, not from the internal data model.

Return meaningful error messages

A 400 Bad Request with no body is unhelpful. Always include an error body that tells the client what went wrong and ideally how to fix it.

{ “error”: “validation_failed”, “message”: “The email field is required.”, “field”: “email” }

Handle pagination for collections

Never return all records in one response. Use pagination — either page-based or cursor-based — and include metadata about total records and next page links.

The principles at a glance

PrincipleOne-line summary
ResourcesEverything is a named thing — identified by a URI
HTTP methodsGET reads, POST creates, PUT replaces, PATCH updates, DELETE removes
StatelessEvery request carries everything the server needs — no sessions stored
Status codesUse the right code — 2xx success, 4xx client error, 5xx server error
Uniform interfaceSame rules for every resource — predictable and consistent
VersioningVersion only for breaking changes — URL versioning is the simplest approach
IdempotencyGET, PUT, DELETE are safe to retry — POST is not
Error messagesAlways tell the client what went wrong and why

Why these principles last

REST principles are not tied to any language, framework, or platform. They describe how resources should behave over HTTP — and HTTP itself has been stable for decades.

Whether you are building a public API, designing an SAP BTP integration, or connecting two internal services, these principles apply. They are the common language that makes APIs predictable across teams and systems.

🔗 Related reading on this site

If you work with SAP, OData — the protocol used by SAP Fiori and BTP — is built on REST principles. The post on OData in SAP covers how these same concepts map into the SAP world: rakeshnarayan.com/articles/

Published on rakeshnarayan.com — Articles

URL: https://rakeshnarayan.com/articles/rest-api-design-principles/