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.
The only optional constraint of REST architecture is code on demand. If a service violates any other constraint, it cannot strictly be referred to as RESTful. Uniform Interface: It is a key constraint that differentiate between a REST API and Non-REST API.
Code-On-Demand means that a server can extend the functionality of a client on runtime, by sending code to it that it should execute (like Java Applets, or JavaScript).
In order for an API to be RESTful, it has to adhere to 6 constraints: Uniform interface. Client — server separation. Stateless.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With