Complex Transaction Processing

You can perform complex transaction processing when a transaction requires a mix of different types of verbs–such as GET, POST, and PUT–that REST is telling the server to take on a row in the request. Use @metadata action tags.
lac52
You can perform complex transaction processing when a transaction requires a mix of different types of verbs–such as GET, POST, and PUT–that REST is telling the server to take on a row in the request. Use 
@metadata
 action tags.
With 
@metadata
 action tags, you can:
  • Specify greater granularity. The tags designate the verb to take on each row. This can provide substantial value in choreographing the persistence actions taken in processing a request.
  • Create and link related data using 
    CA Live API Creator
     services. The services apply to how to process the rows in the request. Reactive logic then applies to each of these row.
    The Business to Business (B2B) API sample includes an example of how to link child rows to parent rows using metadata action tags.
    For more information about this sample, see B2B API Sample.
  • Link child rows to parent rows, without the requirement for the client to supply 
    autonum
     identifier (which they may not know) by inserting 
    @metadata
     action tags. You can use parent sub-resources with these actions.
In this article:
 
 
Metadata Actions Tags
You can use the following metadata action tags:
DELETE
You can delete rows using the 
DELETE
 metadata action tag.
Example:
 
The following JSON deletes a row using the 
name
 field as a unique key:
{
"@metadata" : {
"action":"
DELETE
",
"checksum":"override",
"key":"name"
},
"name":"David 2",
"some_val":202}
You can use this metadata action tag to delete multiple objects in batch by deleting them in a single request. For more information about how to use this metadata action tag to delete in batch, see DELETE.
LOOKUP
You can enable API users to POST data, where your schema uses primary keys that API Server automatically generates and that the sender cannot know, by using the 
LOOKUP
 metadata action tag.
The B2B API sample includes an example of metadata action tags for parent lookup.
For more information about using this metadata action tag, see Lookup Metadata Action.
INSERT
You can insert rows using the 
INSERT
 metadata action tag.
For more information:
UPDATE
You can update rows using the 
UPDATE
 metadata action tag.
Example:
 
The following JSON updates a row:
{
"@metadata": {
"href": "https://foo.my.espressologic.com/rest/foo/bar/v1/Product/123",
"checksum": "123456789ABCDEF",
"action": "
UPDATE
"
},
"unit_price": 0.99
},
For more information about how to use this metadata action tag, see the "Mix and Match Metadata Action Tags in a Request" section.
MERGE_INSERT
You can acquire the data from remote systems that act as the "system of record" for certain data using the 
MERGE_INSERT
 metadata action tag. This metadata action tag is a combination of the 
INSERT
UPDATE
, and the 
LOOKUP
 metadata action tags.
For more information about how to use this metadata action tag, see MERGE_INSERT Metadata Action Tag.
Mix and Match Metadata Action Tags in a Request
You can use different metadata action tags in the same request.
The following JSON inserts the Customer object (using the 
INSERT
 metadata action tag), updates the Product object (using the 
UPDATE
 metadata action tag), and deletes the Address object (using the 
DELETE
 metadata action tag):
[
{
"@metadata": {
"entity": "Customer",
"action": "
INSERT
"
},
"name": "Acme Inc",
"credit_limit": 5000
[
},
{
"@metadata": {
"href": "https://foo.my.espressologic.com/rest/foo/bar/v1/Product/123",
"checksum": "123456789ABCDEF",
"action": "
UPDATE
"
},
"unit_price": 0.99
},
{
"@metadata": {
"href": "https://foo.my.espressologic.com/rest/foo/bar/v1/Address/456",
"checksum": "123456789ABCDEF",
"action": "
DELETE
"
}
}
]