As a newbie i am trying to understand REST and its principles. I have read some articles about it but struggling to undestand Code Demand Constraint which is the only optional constraint. What is it ? How and when to implement it? Any help would be appreciated.
1 Answers
Roy Fielding's thesis, effectively the original source on REST, defines the Code-On-Demand constraint as follows:
REST allows client functionality to be extended by downloading and executing code in the form of applets or scripts. This simplifies clients by reducing the number of features required to be pre-implemented. Allowing features to be downloaded after deployment improves system extensibility. However, it also reduces visibility, and thus is only an optional constraint within REST.
At the time this was written, the web was mostly just static documents and the only "web client" was the browser itself. Now it's commonplace for JavaScript-powered web apps to be consuming REST APIs. This is an example of code on demand - the browser grabs an initial HTML document and supports <script> tags inside that document so that an application can be loaded on-demand.

- 44,526
- 36
- 160
- 222
-
3From [2.3.5](https://www.ics.uci.edu/~fielding/pubs/dissertation/net_app_arch.htm): "Visibility in this case refers to the ability of a component to monitor or mediate the interaction between two other components. Visibility can enable improved performance via shared caching of interactions, scalability through layered services, reliability through reflective monitoring, and security by allowing the interactions to be inspected by mediators (e.g., network firewalls)." – so essentially it's about the ability of middle layers like caches/firewalls to inspect the payload... – mb21 May 11 '18 at 12:32