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("https://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.