Toggle menu

Writing an End Point

An end point is a JavaScript function. It accepts parameters as a JSONRPC request and returns values in a JSONRPC response.

The JavaScript

When you first open the script editor you'll see the basic function signature.

function(params, credentials) {
}

Your function declaration should end with a return statement, which specifies the value to return when your end point is invoked.

Intelligent Code Completion

Common to most IDEs, intelligent code completion is a feature that provides hints and suggestions intelligently as you type. The focus in this editor is on server-side functionality (ie the available JavaScript libraries), and also includes code completion for the end point "this" object.

Intelligent Code Completion - End Points

Use the up and down keyboard arrows followed by the tab or enter key to select a suggestion.

Keyboard Shortcuts

The following keyboard shortcuts are available in the script editor.

KeystrokeDescription
Ctrl+spaceShow suggestions
Alt+iShow type
Alt+oshow documentation
Alt+.Jump to definition
Alt+,Jump back to instance
Ctrl+qRename/refactor variable
Ctrl+.Select all instances of name
Ctrl+/Toggle comment

JavaScript Libraries

Your end points have access to all of the JavaScript Libraries present on the API Server.

Use require('library_name'); to return the library as an object.

End Point Request Builder

The end point request builder is launched using the end point toolbar icon.

It allows you to select an end point that your user has access to, and then view its associated help text and parameter and return schemas.

The "Examples" tab operates in four modes (parameters only, same/different worker invocation, advanced invocation), each of which can show a number of different parameter or test examples. The examples can be copied and pasted into your JavaScript.

Parameters Only

This mode generates the request "params" object, in the same way as the "Get request parameters JSON" action when working in the end point editor. You'll be presented with all of the parameters defined in the end point's schema, just the "required" parameters defined in the schema, and any saved tests that have also been flagged to be used in documentation. This mode is most useful if you only need to know the correct parameter names.

Same Worker Invocation

This mode takes the parameters defined in the schema or any applicable tests and inserts them into an example script that uses the invokeEP function of the end point this object. The end point being called must be running on the same worker as the one making the call.

Different Worker Invocation

This mode is used to call an end point deployed to a different worker than the one making the call. It gives the same examples as described above, but uses callWorkerMethod of the "this" object.

Advanced Invocation

Advanced invocation mode takes the same parameter options described above and places them correctly in a call using the apiclient JavaScript library.

Linting

The script editor provides automatic linting as you write your end point. There's also a Reports you can run to check all of the end points on all of your API Servers for potential errors.

Last modified on 31 July 2023

Share this page

Facebook icon Twitter icon email icon

Print

print icon