Toggle menu

Calling End Points from other End Points

The end points implemented within a solution should aim to provide an API that allows greater independence between the user interface and the actual data storage and business logic.

End points are often best divided into a series of layers. It should be possible to carry out development a layer at a time, working up to the user interface. 

The following points should be considered when designing and implementing a solution:

  • There may be multiple layers of end points - perhaps a series of AJAX end points that are callable from the browser, the API end points themselves, and a series of CRUD-type end points for managing data storage and database interactions
  • If end points are calling other end points deployed to the same worker, use the invokeEP method - see below
  • A CRUD layer of end points should, after initial development, be marked as "internal only". If this is not possible because they are being called directly from somewhere this suggests the layering is not quite right
  • A single "internal only" end point could be used to return a JavaScript object that contains additional functions. This would allow a single end point to provide a set of utility functions
  • Always make use of the trace function in end points. If tracing is not enabled, calling trace has very little impact on performance

invokeEP

The key to successfully creating layers of end points is the correct use of the invokeEP function.

invokeEP is part of the End Point this Object. It is used to make a request to another end point deployed to the same worker. This gives you the option to flag the target end point as "internal", preventing it from being called by anything other than other end points deployed to the same worker. invokeEP is a simple JavaScript call that returns exactly what the invoked end point returns.

Example

This form uses the HTML AJAX Template field to make a request to a public end point called formstraining.trainingInvokeEP. That end point invokes another, internal, end point.

This is what formstraining.trainingInvokeEP looks like:

function(params) {
    return {
        "time" : this.invokeEP("formstraining.trainingInternal", {}),
    };
}

The second, internal, end point returns the date and time, for example:

{
    "id": 680,
    "result": "29/09/2022 @ 15:30",
    "jsonrpc": "2.0"
}

The final result is displayed in a handlebars template:

<p>
    The time is: {{time}}
</p>

If you try calling formstraining.trainingInternal using something like Postman (see Calling End Points Externally for an example that uses Postman) you'll not be able to, even though it's deployed to the ajax library.

The Result

Share this page

Facebook icon Twitter icon email icon

Print

print icon