Give Raise Example

In addition to using create, read, update, delete (CRUD) services to alter data, it is sometimes desirable to create a more explicit API. These are sometimes referred to as an RPC-style API. So, instead of (or in addition to) updating the employee row directly, you can create APIs oriented to specific transactions.
calac41
In addition to using create, read, update, delete (CRUD) services to alter data, it is sometimes desirable to create a more explicit API. These are sometimes referred to as an RPC-style API. So, instead of (or in addition to) updating the
employee
row directly, you can create APIs oriented to specific transactions.
This Business to Business (B2B) example illustrates how you can create a function for the 
employees
 table and the explicitly defined
EmployeeWithRaises
 resource that gives an employee a raise.
In this article:
Use Functions
You can associate functions with tables or resources that you explicitly define in API Creator.
CA Live API Creator
 passes a (table) row object to your function code. If you alter it,
CA Live API Creator
 runs the reactive logic and (if no validations are violated) saves the row to disk. The following image shows the
giveRaise
function in the B2B Northwind API:
Screen Shot 2017-01-04 at 5.02.24 PM.png
This example shows that you can use parameters.
For more information about how to associate functions with tables or resources that you explicitly define in API Creator, see Manage Functions.
Use Functions from Data Explorer
  1. Start Data Explorer.
    For more information about how to start Data Explorer and call functions from Data Explorer, see Data Explorer.
  2. On the toolbar, select
    Entities
    as the endpoint type from the endpoint type drop-down and then select the Employees table from the endpoints drop-down.
  3. In the Main Grid, select the row for which you want to call the function.
  4. In the Form, select the
    giveRaise
     function from the functions drop-down.
    The functions dialog appears.
  5. Enter a Raise Percent, for example 10, and then click
    Submit
    .
    The response displays in the dialog.
The giveRaise function is called on the selected row in the Employees table. If the function contains logic that updates the row, the table row is updated. The Form is updated.
Use Event Sourcing
The event sourcing pattern seeks to retain persistent data for each transaction, for audibility. So, in addition to an Employee row, you might have a series of Employee Salary child rows. You give raises by inserting into the Employee Salary rows.
For more information about this pattern, see Martin Fowler's website.
You can implement this with the following simple
EmployeeRaises
 logic event rule in the B2B Northwind API:
EmployeeRaise event.png
For more information about how to create events, see Event Rule Types.
This example also illustrates the use of loadable libraries, and meta data APIs, as illustrated in the following image:
Screen Shot 2017-01-04 at 6.16.14 PM.png
You can run this in Data Explorer. Insert a row into EmployeeRaises with the new salary.
For more information about how to manage your libraries, see Logic Libraries.