You can use resources for mapping and translation, leveraging their ability to choose/rename attributes and related objects.
Layer7 Live API Creatorhas access to the (table) row by way of the
transformCurrentRow()method. This method provides the transformation logic to choose/rename attributes and related objects. It transforms a table row to a resource instance as a JSON string.
You typically call this method in an event rule.
For more information about event rules, see Event Rule Types.
This method plays a central role in typical business-to-business interactions. This article illustrates the concepts of using this object using the the Business to Business (B2B) sample.
For more information about the B2B sample, see B2B API Sample.
In this article:
Transform Table Rows to Resource Instances
The following sections show how to transform a table row to a resource instance as a JSON string by way of resources and code. The following underlying concepts make this possible:
- Row processing, particularly resource/object mapping, and logic.
- ThetransformCurrentRow()method.The following image shows the workflow for this method:
Partner Order: "Catch" Webhook
PartnerOrderresource in the
B2B NorthwindAPI sample contains multiple tables. The columns that we want are chosen/renamed. The
transformCurrentRow()method provides the following interface logic.
Automatic Generated Key Handling
Consider inserting a
PartnerOrder. When order details are inserted into the database, their OrderID foreign keys must be valid. But Partners cannot and should not provide OrderIDs. OrderIDs are internal implementation. Order numbers are are generated by the database management system (DBMS) on INSERT.
Layer7 Live API Creatorprovides automatic key generation services to obtain the OrderID and cascade the value into the Items objects. This process is automatic and based on schema information about keys and the resource join definition.
For more information about how
Layer7 Live API Creatorreturns the key in update responses, see Automatic Key Generation.
Business Logic: "Throw" Webhook
As a part of row processing,
Layer7 Live API Creatorfinds the relevant logic. For this transaction, the
B2B NorthwindAPI sample includes the
Process Shipper WebHookcommit event rule.
For more information about commit event rules, see Event Rule Types.
The ShipperAPIDef Resource
ShipperAPIDefresource defines what tables we want, what attributes, and how they are renamed. This is the "shape" of the POST that we want to send to our shipper. The
transformCurrentRow()method takes the current Order row (contained in the
logicContextobject) and creates an instance of it per the
ShipperAPIDefresource. As for the incoming
PartnerOrder, resources define the mapping and transformation logic. The next line sends it to the address maintained in the shipper row.
transformCurrentRow() Method Operation
Layer7 Live API Creatorretrieves the value of a specified resource using this method (and associated metadata) and the
The input row is passed by way of the
logicContextobject. It is a
notthe resource row from the incoming request. That ensures that
Layer7 Live API Creatorcan reuse your business logic over the resources that are defined over that table, and regardless of the attributes they contain.
Layer7 Live API Creatorretrieves the value by supplying the primary key from the row. The
getResource()method performs the mapping and transformation logic. There may be little or no correlation between table rows and the resource definition.
For more information: