SyntaxStudy
Sign Up
REST API Beginner 1 min read

What is REST?

REST (Representational State Transfer) is an architectural style defined by Roy Fielding in his 2000 doctoral dissertation. It describes a set of constraints—client-server, stateless, cacheable, uniform interface, layered system, and optional code-on-demand—that, when applied to HTTP, produce scalable and interoperable web APIs. A REST API treats everything as a resource identified by a URL. Operations on resources are expressed through HTTP methods (GET, POST, PUT, PATCH, DELETE), and the server communicates results via HTTP status codes and response bodies, typically JSON.
Example
# REST Constraints illustrated:

# 1. Uniform Interface — resources identified by URL
#    GET  /articles        -> collection
#    GET  /articles/42     -> single resource
#    POST /articles        -> create
#    PUT  /articles/42     -> full replace
#    PATCH /articles/42    -> partial update
#    DELETE /articles/42   -> delete

# 2. Stateless — server holds no client session state
#    Every request must contain all auth info:
#    Authorization: Bearer eyJhbGciOiJIUzI1NiJ9...

# 3. Cacheable — use HTTP cache headers
#    Cache-Control: max-age=3600
#    ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"

# 4. Client-Server — frontend and backend are decoupled
#    The same API can serve a web app, mobile app, and IoT device

# 5. Layered — client can't tell if it talks to origin or proxy
#    Reverse proxies, CDNs, load balancers are transparent

# Example resource representation (JSON):
# {
#   "id": 42,
#   "title": "Understanding REST",
#   "author": { "id": 7, "name": "Alice" },
#   "tags": ["api", "rest"],
#   "createdAt": "2024-03-01T12:00:00Z",
#   "_links": {
#     "self": "/articles/42",
#     "author": "/users/7"
#   }
# }