2010-06-28

REST

REST, or representational state transfer, is a set of architectural principles used in the design of the world wide web, that have proven the key to the web's efficiency and scalability. What are these principles, and how can they be used in the design of programming languages?

Architectural Constraints

REST was described by Roy Fielding in his dissertation. He called out the following set of architectural constraints:

  • Client-Server — separates UI from data storage
  • Stateless Server — improves reliability and scalability
  • Client Cache — reduces some network traffic
  • Uniform Interface — decouples implementations from the services they provide
  • Layered System — means that each component only be concerned with those just below or just above it
  • Code-on-Demand — allows client functionality to be extended by downloading applets or scripts

Principles of REST

A RESTful system is characterized by

  • Addressable Resources
    • Every resource has a (unique) identifier (e.g., URI)
    • Example: http://www.yourcompany.com/products/2443
    • NOT http://www.yourcompany.com/getProduct?id=2443
    • Resources are separate from their representations
  • Representation-Orientation
    • Requests for resources return representations
    • The representation contains the state of the resource
    • The client can update or delete resources through their representations
  • Uniform, Constrained Interface
    • Small, fixed number of verbs
    • Example: In HTTP, GET, PUT, POST, DELETE, HEAD, OPTIONS, TRACE only!
    • An example of a non-constrained interface is an RPC-based protocol (e.g., SOAP, CORBA)
  • Self-Descriptive Messages
    • Messages include all the information necessary to be processed
    • Example: Internet Media Types
  • Stateless Server
    • With no shared context on the server, client requests are independent
    • Servers can be simpler, "more" multithreaded, easier to monitor, reliable, scalable, etc.
  • Cacheability
    • Responses indicate whether the client can cache the data or not
    • Obviously can cut down on network traffic if the client knows it doesn't have to ask for the same data again
  • HATEOAS
    • Hypermedia as the engine of application state
    • Representations should include links to related resources

Can we apply any of these principles to programming language design?

System-wide unique identifiers

The idea of identifiers having wide scope, whether unique across a system or unique across the entire world (such as URIs) exists in many forms: UUIDs, MAC addresses, public IP addresses, etc. In programming languages, Java package names are encouraged to be globally unique by using a (reversed) DNS name over which you have control.

Resource/Representation Separation

A limited, fixed, set of verbs

Self-descriptive content

Statelessness

Cachability

Linkage of Representations

No comments:

Post a Comment