With 4D 20 R5, we released singletons. And with 4D 20 R6, we now allow you to directly call the exposed functions of your shared singletons through REST calls. Similarly, you can use the exposed functions of your shared singletons in events when designing your Qodly Pages. Let me delve deeper into these new capabilities.
HDI REST and Qodly Support of Singletons
Let’s say you want to create a REST service that is not linked to a specific data class.
Easy!
First, let’s create a shared singleton with an exposed function, the one you want to call through REST:
//class mySingleton
shared singleton Class constructor()
exposed Function myFonction($value : Integer)
//code
Then, let’s look at the catalog by checking the JSON returned by myServer/rest/$catalog/$all. I see that my singleton just appeared with its exposed function:
"singletons": [ { "name": "mySingleton", "methods": [ { "name": "myFonction", "allowedOnHTTPGET": false, "exposed": true } ] } ],
I can now make a REST call to myServer/rest/$singleton/mySingleton/myFonction to directly execute my exposed function.
Of course, you can restrict calls to specific functions or singletons by configuring privileges in the roles.json file.
Inside Qodly, it’s even easier. When configuring events, you can choose your shared singletons exposed functions like any data class exposed function:
Qodly Studio shows my singleton inside the catalog and allows me to choose its exposed functions for events
And similarly, you can configure rights to execute singletons and their exposed functions through the privileges screen:
Qodly Studio roles and privileges page allows me to configure my singleton’s access rights
If you want an easy-to-use example of what you can perform with singletons, I encourage you to check the HDI on singletons.
We hope these two features will ease your use of singletons.
If you have comments or remarks, don’t hesitate to bring them to our forum!