Jolie meets JavaScript
Starting today, JOLIE services can exploit the JavaScript language!
As usual we are not speaking of mixing JOLIE code with another language, which would result in incomprehensible JOLIE programs. We are instead speaking of the insertion of another language in JOLIE's service-oriented paradigm, by means of the embedding mechanism (which we are detailing in our new, shiny tutorials, to be published really soon).
Embedding a JavaScript service goes like this:
The JavaScript API for accessing structured JOLIE data is the same as the one for Java. Let us see how the Math service is implemented:
Voilà! Simple, isn't it?
Support for other scripting programming languages will be introduced in the future, stay tuned! =)
As usual we are not speaking of mixing JOLIE code with another language, which would result in incomprehensible JOLIE programs. We are instead speaking of the insertion of another language in JOLIE's service-oriented paradigm, by means of the embedding mechanism (which we are detailing in our new, shiny tutorials, to be published really soon).
Embedding a JavaScript service goes like this:
// main.ol
include "console.iol"
// Standard JOLIE service declaration
outputPort Math {
RequestResponse: sum
}
embedded {
// We load our JavaScript file as the JS service
JavaScript:
"mathservice.js" in Math
}
main
{
// Now we can call JS as every other service type supported by JOLIE
with( request ) {
.addend[0] = 2;
.addend[1] = 4;
.addend[2] = 1;
.addend[3] = 3
};
sum@Math( request )( response );
println@Console( response ) // Will print 10
}
The JavaScript API for accessing structured JOLIE data is the same as the one for Java. Let us see how the Math service is implemented:
// mathservice.js
function sum( request )
{
var addends = request.getChildren( "addend" );
var total = 0;
for( var i = 0; i < addends.size(); i++ ) {
total += addends.get( i ).intValue();
}
return total;
}
Voilà! Simple, isn't it?
Support for other scripting programming languages will be introduced in the future, stay tuned! =)