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:
- The Package
demo006-http-to-sqlwill 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.
Line by Line: How this "HTTP (header based routing) to SQL" demo works
- Routing the request payload to an SQL Database.
\\code\demo006\servicesis the service that gets called when a request is made to the
- 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
ECOMMERCEthis line gets executed, mapping the request payload received by this service to the SQL service that saves the data in the
- 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
- Line 6:
Case $null\ This line is a fallback option if there is no header value provided.
- Line 4:
- Line 3:
- 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.