We had a request from a customer asking us if they could implement different integration logic depending on the header of a HTTP request.
We built this demo so that others could learn from this example should they also need to implement logic that is based on a value in the header of a HTTP payload.
In this use case we will accept a payload via HTTP, inspect the header of the request and then depending on the value in the header, write the payload to a SQL database.
watch this use case in action
Line by Line: How this "HTTP (header based routing) to SQL" demo works
Routing the request payload to an SQL Database.
The RoutingService located at \\code\demo006\services is the service that gets called when a request is made to the /sku REST endpoint.
Line 3: Fork x_sku_entity: \ When the service gets called, the request payload and header are passed into this service. It will first check the header value before it decides what to do with the request payload received.
Line 4: Case ECOMMERCE \ If the header value received is ECOMMERCE this line gets executed, mapping the request payload received by this service to the SQL service that saves the data in the ECOMMERCE_SKU table.
Line 5: Case INVENTORY \ If the header value received is INVENTORY, it will do the same action with line 4, except that it saves the request payload to the INVENTORY_SKU table
Line 6: Case $null \ This line is a fallback option if there is no header value provided.
If the request payload received by this service does not match the target entity, the request will still be processed, only mapping the properties that are common to both entities.
Within either Martini Desktop or Martini Online select the "HTTP to SQL" demo from the Welcome Screen and click Install:
The Packagedemo006-http-to-sql will be automatically downloaded. Right-click the Package and click Start. A green icon will indicate it has started:
Documentation containing a Test Procedure to run the demo is included in the Package readme file \resources\readme\readme.md. The readme file is automatically opened when the Package is started.
The Test Procedure will guide you through the process to send a payload via HTTP and invoke the service logic to inspect the HTTP header and then, depending on a value in the header, write the payload to a SQL database.