Code on demand

Code on demand with REST

In the paper Architectural Styles and the Design of Network-based Software Architectures by Roy Thomas Fielding, REST is defined. Today, when people think of REST, they often associate it with CRUD operations, more or less. However, one of the properties defined in the paper is ‘Code on Demand,’ where the client can request a script or binary from the server (similar to what happens when a browser requests JavaScript files to extend the behavior of a web page).

It’s nice, but it’s not exclusive to the web world. Take a look at this example in Qt:

import QtQuick
import QtQuick.Controls 2.5

Page {
    id: page
    Button {
        text: "load"
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        onClicked: {
            loader.source = new URL("http://server/test.qml")
        }
    }

    Loader {
        id: loader
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter
    }
}

When you click the button, we load:

import QtQuick
import QtQuick.Controls 2.5

Item {
    anchors.fill: parent

    Column {
        anchors.fill: parent
        TextField {
            width: dp(100)
            placeholderText: "Write here"
        }
        Button {
            text: "Ok"
            onClicked: {
            }
        }
    }
}

I think that the power of code on demand is sometimes underrated, yet we have the tools to leverage it. Please try to use it in a real case.

share this post with friends

Picture of Nicola De filippo

Nicola De filippo

I'm a software engineer who adds to the passion for technologies the wisdom and the experience without losing the wonder for the world. I love to create new projects and to help people and teams to improve

Leave a comment

Your email address will not be published. Required fields are marked *

Who I am

I'm a software engineer who adds to the passion for technologies the wisdom and the experience without losing the wonder for the world. I love to create new projects and to help people and teams to improve.

Follow Me Here

Get The Latest Updates

Periodically receive my super contents on coding and programming

join the family;)

Recent Posts