USE CASE: DATA INTEGRATION

How to switch logic based on the header of a HTTP payload

David Brown  |  August 12, 2021

http-to-sql

Header based routing to a sql database

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.

How to download & run this "HTTP (Header based routing) to SQL" demo

  • If you haven't already done so, get yourself a Martini.
  • Within either Martini Desktop or Martini Online select the "HTTP to SQL" demo from the Welcome Screen and click Install:
    screenshot-welcome-screen
  • The Packagedemo006-http-to-sql will be automatically downloaded. Right-click the Package and click Start. A green icon will indicate it has started:
    screenshot-package
  • 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.
    screenshot-documentation
  • 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.

Line by Line: How this "HTTP (header based routing) to SQL" demo works

screenshot-service

  • 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.
cta-left cta-right
Demo

Want a ringside seat to the action?

Book a demo to see how our fully integrated platform could revolutionise your organisation and help you wrangle your data for good!

Book demo