API Reference

ASG-Studio provides various server script APIs that you can use while developing applications. The server script helps in creating a proxy layer for a service, create back-end logic to access database and more. You can create server logic and web services as JavaScript code. Web Service is a server script which is accessible from the internet to do the desired functionality.

$s

$s is a global Server Script object that should be appended with every database or external webservice function.

You can write server script for the purpose of delivering the below possibilities but not limited to:

  • Creating proxy layer for a web service to avoid any sensitive information being revealed
  • To implement a new functionality using code at the back-end

Perform the following steps:

  1. Launch ASG Studio.
  2. Open the project in which you want to create Server Script.
  3. Click the context menu, select New, and click Server Script.
  4. Enter a name for the Server Script file and click OK.
  5. In the script editor write your script and click Save.
  6. Click Copy to copy the path of the sever script file. You can use this path as URL to execute the server script.

Following Server Script APIs are currently available with ASG-Studio:


Common APIs

executeScript

Use this method to execute the script that is provided input.

Syntax: $s.executeScript(script)

Parameters:

  • script: (string) The script to execute.

Exception: Throws error if there is any issue in the script execution.

getParameter

Use this method to get the parameter value from the request.

Syntax: $s.getParametert(paraketerKey)

Parameters:

  • parameterKey: (string) The key name of the parameter.

Return: String

getPart

Use this method to read binary data from request as StudioBlob at specified key.

Syntax: $s.getPart(parameterKey)

Parameters:

  • parameterKey: (string) The key name of the part parameter.

Return: StudioBlob

Exception: Throws error if there is any issue in converting part value to StudioBlob or reading the part value from request.


Response APIs

sendResponse

Use this method to write content to response either as base64 string or as binary.

Syntax: $s.sendResponse(blob, contentType, fileName, isText, contentDisposition)

Parameters:

  • blob: (studioblob) The value that is to send in response.
  • contentType: (string) Type of content that is to send in response.
  • fileName: (string) The name of the content file that is to send in response.
  • isText: (boolean) The value to detect whether to send the content as base64 string or as binary.
  • contentDisposition: (boolean) The value to detect whether to directly download or render the content.

Exception: Throws error if there is any issue in writing content to response object.

setStatus

Use this method to set the HTTP response code.

Syntax: $s.setStatus(code)

Parameter:

  • code: The HTTP response code to help user aware of whether service call is success or failure.

setData

Use this method to set the response data that need to be sent as data or JSON object or JSON array.

Syntax: $s.setData(data)

Parameters:

  • data: (string / JSON object / JSON array) The output to send to the user.

Exception: Throws error if there is any issue in writing data to response object.

setMessage

Use this method to set the HTTP response message.

Syntax: $s.setMessage(message)

Parameters:

  • message: (string) The content to help user know what is the response of service call.

Exception: Throws error if there is any issue in writing data to response object.


Database Query APIs

execute

Use this method to perform insert, update, or delete query operation and get the results.

Syntax: $s.execute()

Return: String

Exception: Throws error if there is any issue in the query execution.

getBlob

Use this method to read a blob field value from the query results.

Syntax: $s.getBlob(parameter)

Parameters:

  • parameter: (string) Name of the parameter whose value is to retrieve.

Return: StudioBlob

query

Use this method to initialize database query operation.

Syntax: $s.query(datasourceName, query)

Parameters:

  • datasourceName: (string) Name of the datasource on which to perform the query.
  • query: (string) The content of query to execute.

Exception: Throws error if the query initialization fails.

queryDb

Use this method to perform select query operations and get results

Syntax: $s.queryDb()

Return: String

Exception: Throws error if the query execution fails.

setBigDecimal

Use this method to set the BigDecimal value to the Query Statement.

Syntax: $s.setBigDecimal(position, parameterKey)

Parameters:

  • position: (integer) The position in the query statement at which the value needs to set.
  • parameterKey: (string) The name of the parameter whose value is to set.

Exception: Throws error if there is an issue in setting or converting the value to statement value.

setBytes

Use this method to set the Binary value to the Query Statement.

Syntax: $s.setBytes(position, parameterKey)

Parameters:

  • position: The position in the query statement at which the value needs to set.
  • parameterKey: (string) The name of the parameter whose value is to set.

Exception: Throws error if there is an issue in setting or converting the value to statement value.

setDate

Use this method to set the Date value to the Query Statement.

Syntax: $s.setDate(position, parameterKey)

Parameters:

  • position: (integer) The position in the query statement at which the value needs to set.
  • parameterKey: (string) The position in the query statement at which the value needs to set.

Exception: Throws error if there is any issue in setting or converting the value to statement value.

setInteger

Use this method to set the Integer value to the Query Statement.

Syntax: $s.setInteger(position, parameterKey)

Parameters:

  • position: (integer) The position in the query statement at which the value needs to set.
  • parameterKey: (string) The position in the query statement at which the value needs to set.

Return: Throws error if there is any issue in setting or converting the value to statement value.

setLong

Use this method to set the Long value to the Query Statement.

Syntax: $s.setLong(position, parameterKey)

Parameters:

  • parameterKey: (string)

Parameters:

  • position: (integer) The position in the query statement at which the value needs to set.
  • parameterKey: (string) The position in the query statement at which the value needs to set.

Return: Throws error if there is any issue in setting or converting the value to statement value.

setObject

Use this method to set the Object value to the Query Statement.

Syntax: $s.setObject(position, parameterKey)

Parameters:

  • position: (integer) The position in the query statement at which the value needs to set.
  • parameterKey: (string) The name of the parameter whose value is to set.

Exception: Throws error if there is an issue in setting or converting the value to statement value.

setString

Use this method to set the String value to the Query Statement.

Syntax: $s.setString(position, parameterKey)

Parameters:

  • position: (integer) The position in the query statement at which the value needs to set.
  • parameterKey: (string) The name of the parameter whose value is to set.

Exception: Throws error if there is an issue in setting or converting the value to statement value.

setTime

Use this method to set the Time value to the Query Statement.

Syntax: $s.setTime(position, parameterKey)

Parameters:

  • position: (integer) The position in the query statement at which the value needs to set.
  • parameterKey: (string) The position in the query statement at which the value needs to set.

Exception: Throws error if there is any issue in setting or converting the value to statement value.

setTimestamp

Use this method to set the Timestamp value to the Query Statement

Syntax: $s.setTimestamp(position, parameterKey)

Parameters:

  • position: (integer) The position in the query statement at which the value needs to set.
  • parameterKey: (string) The position in the query statement at which the value needs to set.

Exception: Throws error if there is any issue in setting or converting the value to statement value.