Building a RESTFUL Web Service Ready for production

What is REST

Stands for Representational State Transfer

  • Its a set of constraints

Why use REST

We should use it in order to mimic the Web Architecture, a model that has proben to be very successful.

Which are the REST constraints

THE CLIENT - SERVER CONSTRAINT

  • Enforces a separation of concerns
  • Allows independent evolution of
    • Clients
      • Like
        • browsers or others
    • Servers
      • Like
        • Apache or Nginx or others

THE STATELES CONSTRAINT

  • Client-Server communication must be stateless between requests
  • A request should contain all necessary data for the Server to complete it
  • All session data should be returned to the client at the end of each Request
  • The client side must contain all the data related to the session

THE CACHE CONSTRAINT

  • Responses from the server are explicitly labeled as cacheable or non-cacheable
  • Requests pass through a cache component
  • The goal is to match the infrastructure of the existen Web infrastructure

THE UNIFORM CONTRACT CONSTRAINT - API

  • The service and all clients must share a single uniform technical interface
  • To be reusable by a wide range of clients and over a broad range of interactions
  • It needs to provide generic, high-level, abstract capabilities

THE LAYERED SYSTEM CONSTRAINT

  • Builds on Client-Server to allow for intermediaries / middleware
  • These intermediaries must be transparent
  • Information Hiding
    • Simplifies distributed architecture

REST Terminology

  • Resource
    • Any sort of information that can be refert to via a URI 
  • Representation
    • The current state of a resource in a specific format
    • A sequence of bytes plus representation metadata to describe those bytes
      • Like
        • XML
  • Hypermedia Type
    • Specific format for a resource with aditional options
      • JSON is not Hypermedia
      • JSON plus other extra options might be a Hypermedia Type