What is 'code on demand' in REST, and why is it an optional constraint?

Last updated 29 June 2026

  • Code on demand lets the server send executable code (e.g. JavaScript) to extend client behavior at runtime, like a browser running a page's scripts.

  • It is the only optional REST constraint: an API is fully RESTful without it, and it reduces client simplicity and visibility.

  • Pro: dynamic feature delivery with fewer client deployments. Con: security risks, so most JSON APIs skip it.

  • https://www.redhat.com/en/blog/rest-architecture
  • https://www.mindsetconsulting.com/rest-apis-how-rest-apis-work-and-the-steps-we-need-to-follow-to-implement-them/
  • https://dev.to/educative/13-rest-api-interview-questions-you-need-to-know-pnd
  • https://towardsdatascience.com/rest-api-the-architectural-constraints-fc4876b41e3d/
  • https://dev.to/turalsuleymani/rest-in-depth-or-what-exactly-rest-is-32a7
  • https://stackoverflow.com/questions/32094952/code-demand-constraint-for-restful-apis
All REST API interview questions