banty01

Difference between JavaScript endpoints & Functions

Blog Post created by banty01 Employee on Nov 29, 2017

One of the CA Live API Creator questions that seems to cause the most confusion is "the difference between an LAC top level function and a JavaScript (JS) endpoint?".  Both are written in JavaScript and are called by the GET method.  Both can return a single value or a JSON object.  The biggest difference is that the top level function can also include user defined parameters.  These parameters can be both types (string, number, boolean) and marked as required.  While a JavaScript Resource can refer to the URL parameters - the testing and typing must be done by the developer.  Another advanced feature of a function is that it can be associated with one or more tables, views, or normal resources.  For example, you can access a single row (1000 is employee id) of a table (employe) and pass a named parameter (/employee/1000?giveRaise=10).  So this verb (giveRaise) is the named parameter and the JavaScript will give the developer full access to the 'row' object for the resource 'employee' id=1000.  This means that using a GET - the developer can pass in values that are used to calculate the raise percentage and update the row with a single line of JavaScript (row.salary = (parameter.giveRaise * row.salary) + row.salary; ).  Finally, the LAC security model for functions can limit the 'execute' to specified named user roles.  So only the manager can give his own employees a raise.  For more information - see the documentation.

Outcomes