Understanding REST Architecture

1. Understanding REST Principles

REST (Representational State Transfer) is an architectural style for distributed hypermedia systems defined by Roy Fielding (2000). It is not a protocol or standard but a set of constraints.

ConstraintDescriptionRequired
Client-ServerSeparation of concerns; UI vs data storageYes
StatelessEach request contains all info needed; no server session stateYes
CacheableResponses must be implicitly/explicitly cacheable or notYes
Uniform InterfaceStandardized methods, identifiers, hypermediaYes
Layered SystemClient cannot tell if connected to end server or intermediaryYes
Code on DemandServer can extend client by transferring executable codeOptional

2. Understanding Resource-Based Architecture

Everything is a resource identified by a URI. Resources are nouns; verbs come from HTTP methods.

ConceptDefinitionExample
ResourceAny addressable entity (user, order, product)/users/42
Resource IdentifierURI uniquely identifying a resourcehttps://api.example.com/orders/100
RepresentationSerialized form of resource stateJSON, XML, HTML
CollectionContainer of resources/users
SingletonOne-of-a-kind resource/users/42/profile

3. Understanding Uniform Interface Constraints

Sub-ConstraintMeaning
Identification of ResourcesEach resource has a unique URI
Manipulation via RepresentationsClients modify resources by sending representations
Self-Descriptive MessagesEach message has enough info to process it (Content-Type, etc.)
HATEOASResponses include links to discover next actions

4. Understanding Stateless Communication

Server stores no client context between requests. Session state lives on the client.

AspectStateless (REST)Stateful
AuthToken sent every requestServer-side session
ScalabilityHorizontal scaling trivialSticky sessions required
ReliabilityServer failure does not lose stateState lost on failure
BandwidthHigher (full context per request)Lower
Warning: Cookies/sessions stored server-side violate statelessness. Use JWT/Bearer tokens instead.

5. Understanding Cacheability Requirements

MethodCacheable by DefaultNotes
GETYesCache freely with proper headers
HEADYesSame as GET, no body
POSTConditionalOnly if explicit Cache-Control set
PUT/PATCH/DELETENoMutating operations

6. Understanding Layered System Architecture

Client → CDN → API Gateway → Load Balancer → App Server → DB
        (cache) (auth/rate)   (routing)      (business)
      
LayerPurpose
CDNEdge caching, static asset delivery
API GatewayAuth, rate limiting, routing
Load BalancerDistribute traffic across instances
ApplicationBusiness logic
Data StorePersistence layer

7. Understanding Code on Demand

Optional constraint: server delivers executable code (JavaScript, applets) to extend client functionality.

Use CaseExampleStatus
Browser JSServer returns HTML+JS bundleCommon
PluginsJava applets, FlashObsolete
WebAssemblyCompiled modules served by APIModern

8. Understanding REST Maturity Model

Richardson Maturity Model (RMM) measures how RESTful an API is.

LevelNameCharacteristic
0Swamp of POXOne URI, one method (POST), RPC-style
1ResourcesMultiple URIs, still single method
2HTTP VerbsProper use of GET/POST/PUT/DELETE + status codes
3Hypermedia (HATEOAS)Responses include links to related actions

9. Understanding RESTful vs REST-like APIs

AspectRESTful (Strict)REST-like (Pragmatic)
HATEOASRequiredOptional/omitted
HypermediaDiscoverableDocumented out-of-band
AdoptionRareMost public APIs (GitHub, Stripe)
Maturity Level32

10. Understanding REST vs SOAP Differences

FeatureRESTSOAP
ProtocolHTTP onlyHTTP, SMTP, TCP
FormatJSON, XML, anythingXML only
StyleArchitectural styleProtocol with strict spec
StandardsConventions, OpenAPIWSDL, WS-* (Security, AT)
PerformanceLighter, cacheableHeavier (XML envelope)
Use CaseWeb/mobile APIsEnterprise, banking, legacy
Error HandlingHTTP status codesSOAP Fault element