Setting up webservices

A moduledefinition shall declare

    <webservice name="servicename" transports="jsonrpc" library="servicelibrary.whlib" requirewhaccount="false" primarytrans="none">

Transports can be one or more of

JavaScript integration with module-webdesigns.

The easiest way to use to services is to set up a .rpc.json file (this exact extension is required!) with the following contents:

{ "services": [ "modulename:servicename" ] }

which will setup a function returning a promsie for every function in your library.

Then you can invoke the functions using async/await:

import * as myrpc from "./services.rpc.json";
async function()
  let result = await myrpc.myfunction(param1, param2);

The JSONRPC object

To specify options to use when running the request, use the 'rpcOptions' object:

 myrpc.rpcOptions.timeout = 30000; // Set timeout to 30 seconds

If you want more control over the JSONRPC object, for example to add 'requeststart' or 'requestend' event listeners or for referencing JSONRPC error codes use the myrpc.rpcObject property

HareScript considerations when handling JSON/RPC

An empty JavaScript arrays shows up as a DEFAULT VARIANT ARRAY in HareScript, which can easily crash code. Arrays with at least one member are converted to the proper HareScript ARRAY type if possible, butif the members are of mixed type the array will still be of type VARIANT ARRAY. Use EnforceStructure to normalize received JSON data.