Code on Demand

Optional transfer of executable code

“REST allows client functionality to be extended by downloading and executing code in the form of applets or scripts.” – Roy Fielding

When to use

Web Apps (JavaScript).

Why it matters

  • Flexibility: You can update the client logic by deploying new scripts to the server. The client downloads them and runs the new features.

Signs of Violation

  • (This is optional, so you can’t really “violate” it by not doing it, but rigidly forcing clients to update binaries is the opposite).

Explanation

Problem

If logic is hardcoded in the client binary, you have to reinstall the client to update logic.

Solution

Send the logic (Code) over the wire. This is how the web works (sending JS to the Browser).

Real world analogy

A player piano. You buy the piano once. You buy new scrolls (Code) to play new songs. You don’t buy a new piano for a new song.

Pros and Cons

Pros Cons
  • Instant updates
  • Rich Clients
  • Security risks (XSS, Eval)
  • Comparison

    • Mobile Apps vs Web Apps: Mobile (Binary update via App Store) vs Web (Code on Demand via URL).

    Code example

    Typescript

    Good (Adherence)

    PHP

    Good (Adherence)