Skip to main content

RESTful Engine JavaScript Client Reference

This article describes how to get the Fluent RESTful V2 JavaScript client installed, as well as a list of all methods and models defined in the client.

Setting Up the Client

note

To see a sample application using the Fluent RESTful V2 JavaScript client, please refer to our sample JavaScript client application github page.

To set up the client, run one of the following commands:

npm install --save windwardrestapi

or to install globally:

npm install -g windwardrestapi

Then in your project, import the client and the models you need:

import pkg from 'windwardrestapi';
const { WindwardClient, Template, Xml_10DataSource, OutputFormatEnum } = pkg;

Then to initialize the client:

const client = new WindwardClient("http://your-restful-engine-url");

Now the client is set up and you can call the different methods associated with it.

Client Models

info

This section will go over the relevant models associated with the client that you will use. Import the models you need from the package: import pkg from 'windwardrestapi'; const { WindwardClient, Template, Xml_10DataSource, OutputFormatEnum, ... } = pkg;

Template

These are the parameters for the Template object constructor:

:param outputFormat : The desired output file type (set using OutputFormatEnum)
:type OutputFormatEnum

:param datasources : The datasources to apply to the template. The datasources are applied simultaneously.
:type DataSource[]

:param callback : If set, this url will be called with a POST when a job completes. If the text "{guid}" is in the url, that text will
be replaced with the Guid for the callback.
:type string

:param data : The file path for your template (the client will encode to base64) (only use if connectionString is undefined)
:type string : string representation of the file path

:param connectionString : The connection string to your template file (only use if data is undefined)
:type string

:param format : The format of the template to be processed (if left empty it will auto populate)
:type string

:param properties : Fluent properties for this report. These override any properties set in the configuration file on the server side.
:type Property[] : An array of Property objects

:param parameters : A set of input parameters for this report. The parameters are global and shared among all data sources.
:type Parameter[] : An array of Parameter objects

:param tag : A tag you want to assign to the template.
This is passed in to the repository job handlers and is set in the final generated Report object
:type string

:param trackImports : Return all imports with the generated document
:type boolean

:param trackErrors : Enable or disable the error handling and verify functionality.
:type number

:param mainPrinter : If you are using printer output use to specify main printer. Printer must be recognized by Network
:type string

:param firstPagePrinter : Set first page printer if main printer is already set
:type string

:param printerJobName : Assign the print job a name
:type string

:param printCopies : Set number of copies the print job should print
:type number

:param printDuplex : Selects the printers duplex mode
:type string

Here is the constructor for the Template object:

new Template(outputFormat, datasources, callback, data, connectionString, format, properties,
parameters, tag, trackImports, trackErrors, mainPrinter,
firstPagePrinter, printerJobName, printCopies, printDuplex)

Only set the input parameters that apply to your report. You must have either the data input parameter or the connectionString input parameter set.

XML 1.0 Data Source

These are the input parameters for the XML 1.0 data source constructor:

:param name : The datasource name that maps to the datasource attribute in tags
:type string

:param connectionString : The connection string to the XML1 data (only use if data is undefined)
:type string

:param data : The file path to the XML1 data file (only use if connectionString is undefined)
:type string : the file path to the XML1 data file as a string

:param schemaConnectionString : The connection string to the XSD file. undefined if no schema
:type string

:param type : The datasource type (defaults to DatasourceTypeEnum.XML)
:type DatasourceTypeEnum

This is how you instantiate the object:

const xmlDS = new Xml_10DataSource("MANF_DATA_2009", undefined, "./data.xml");

XML 2.0 Data Source

These are the input parameters for the XML 2.0 data source constructor:

:param name : The datasource name that maps to the datasource attribute in tags
:type string

:param connectionString : The connection string to the XML2 data (only use if schemaData is undefined)
:type string

:param schemaData : The file path to the XSD schema file
:type string

:param schemaConnectionString : The connection string to the XSD file
:type string

:param type : The datasource type (defaults to DatasourceTypeEnum.XML2)
:type DatasourceTypeEnum

This is how you instantiate the object:

const xml2DS = new Xml_20DataSource("myXml2DS", "./data.xml", undefined, "./schema.xsd");

SQL Data Source

These are the input parameters for the SQL data source constructor:

:param name : The datasource name that maps to the datasource attribute in tags
:type string

:param connectionString : The connection string to the SQL data
:type string

:param data : Optional inline data
:type string

:param type : The datasource type (defaults to DatasourceTypeEnum.SQL)
:type DatasourceTypeEnum

This is how you instantiate the object:

const sqlDS = new SqlDataSource("mySqlDS", "Server=myServer;Database=myDB;...");

JSON Data Source

These are the input parameters for the JSON data source constructor:

:param name : The datasource name that maps to the datasource attribute in tags
:type string

:param connectionString : The connection string to the JSON data file (only use if data is undefined)
:type string

:param data : The file path to the JSON data file (only use if connectionString is undefined)
:type string : the file path to the JSON data file as a string

:param type : The datasource type (defaults to DatasourceTypeEnum.JSON)
:type DatasourceTypeEnum

This is how you instantiate the object:

const jsonDS = new JsonDataSource("myJsonDS", undefined, "./data.json");

OData Data Source

These are the input parameters for the OData data source constructor:

:param name : The datasource name that maps to the datasource attribute in tags
:type string

:param connectionString : The connection string to the OData data
:type string

:param type : The datasource type (defaults to DatasourceTypeEnum.ODATA)
:type DatasourceTypeEnum

This is how you instantiate the object:

const oDataDS = new ODataDataSource("myODataDS", "https://services.odata.org/...");

Salesforce Data Source

These are the input parameters for the Salesforce data source constructor:

:param name : The datasource name that maps to the datasource attribute in tags
:type string

:param connectionString : The connection string to the Salesforce data
:type string

:param type : The datasource type (defaults to DatasourceTypeEnum.SALESFORCE)
:type DatasourceTypeEnum

This is how you instantiate the object:

const salesforceDS = new SalesforceDataSource("mySalesforceDS", "username=...;password=...;...");

Salesforce OAuth Data Source

These are the input parameters for the SalesforceOAuth data source constructor:

:param name : The datasource name that maps to the datasource attribute in tags
:type string

:param connectionString : The connection string to the SalesforceOAuth data
:type string

:param type : The datasource type (defaults to DatasourceTypeEnum.SALESFORCEOAUTH)
:type DatasourceTypeEnum

This is how you instantiate the object:

const salesforceOAuthDS = new SalesforceOAuthDataSource("mySalesforceOAuthDS", "clientId=...;clientSecret=...;...");

Parameter

These are the input parameters for the Parameter constructor:

:param name : The name of the parameter
:type string

:param value : The value of the parameter. You can pass any primitive or null.
:type any

The template object takes in an array of Parameter objects, so if you have multiple, add them to an array and pass them in:

const params = [
new Parameter("varName1", "value1"),
new Parameter("varName2", 42)
];

Client Methods

Client Constructor

Input Parameters:

:param baseUrl : The base URL to your RESTful engine instance
:type string

:param licKey : Optional license key if you want to process a report with a specific license key.
:type string

This is how you would call it:

const client = new WindwardClient("http://your-restful-engine-url");
// or with a license key:
const client = new WindwardClient("http://your-restful-engine-url", "your-license-key");

client.getVersionInfo()

This method returns the version information for the REST engine and the local client. No input parameters. How to call:

const version = await client.getVersionInfo();

Returns version data.

client.postDocument(template)

This method is used to post the constructed template object to the RESTful engine. Takes in a Template object. How to call:

const document = await client.postDocument(template);

Returns a Document object.

client.getDocumentStatus(guid)

This method is used to get the status of the document being processed. You MUST use this method to check the status of the document before retrieving it. How to call:

const status = await client.getDocumentStatus(document.guid);

This is how we recommend using this in your application:

let status;
do {
await new Promise(resolve => setTimeout(resolve, 500));
status = await client.getDocumentStatus(document.guid);
} while (status !== 302);

We need to wait until getDocumentStatus() returns 302. The method returns HTTP status codes.

client.getDocument(guid)

This method is used to retrieve the generated document after processing. You pass to it the Guid:

const result = await client.getDocument(document.guid);

This method returns the document object.

client.deleteDocument(guid)

This method is used to delete a generated document. You pass to it the Guid:

const status = await client.deleteDocument(document.guid);

Returns a status code.

client.postMetrics(template)

This method takes in a Template object and posts it to the engine to get metrics. How to call:

const metrics = await client.postMetrics(template);

Returns a Metrics object.

client.getMetricsStatus(guid)

This method gets the status of the metrics as it is being processed by the engine. Takes in a Metrics object Guid. How to call:

const status = await client.getMetricsStatus(metrics.guid);

Returns a status code.

client.getMetrics(guid)

This method retrieves the generated metrics after processing. Takes in a Metrics object Guid. How to call:

const result = await client.getMetrics(metrics.guid);

Returns a metrics object.

client.deleteMetrics(guid)

This method deletes a generated metrics result. Takes in a Metrics object Guid. How to call:

const status = await client.deleteMetrics(metrics.guid);

Returns a status code.

client.postTagTree(template)

This method takes in a Template object and posts it to the engine to get the tag tree of tags in the template. How to call:

const tagTree = await client.postTagTree(template);

Returns a TagTree object.

client.getTagTreeStatus(guid)

This method gets the status of the tag tree as it is being processed by the engine. Takes in a TagTree object Guid. How to call:

const status = await client.getTagTreeStatus(tagTree.guid);

Returns a status code.

client.getTagTree(guid)

This method retrieves the generated tag tree after processing. Takes in a TagTree object Guid. How to call:

const result = await client.getTagTree(tagTree.guid);

Returns a TagTree object.

client.deleteTagTree(guid)

This method deletes a generated tag tree. Takes in a TagTree object Guid. How to call:

const status = await client.deleteTagTree(tagTree.guid);

Returns a status code.