Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Demand Constraint for RESTful APIs

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.

like image 584
Tartar Avatar asked Aug 19 '15 12:08

Tartar


People also ask

What are the constraints of RESTful API?

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.

What is code on demand 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).

Which constraint must be adhered by API to be RESTful?

In order for an API to be RESTful, it has to adhere to 6 constraints: Uniform interface. Client — server separation. Stateless.


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.

like image 79
mahemoff Avatar answered Sep 28 '22 05:09

mahemoff