Share via


Logic app:Receive REST Untyped http request as Json(typed) message

Introduction

Hello friends, now you could create a REST Service which receives your http(non-typed) requests as JSON typed a message and validate against an XML schema and Transform them in Azure Logic App. We will see that in Logic App.

Create JSON Schema

First, we need to create a JSON schema. For that, there are many online tools which give JSON schema, one of them http://jsonschema.net/index.html#/. First Convert your XML into JSON instance then try converting JSON schema.

Import Schemas and Maps

To import or create your maps and schemas in Azure we need to have "Integration Account" which could hold maps and schemas that could be used inside logic app later. 

There are 2 schemas Student and Employee looks like below,

and below is the XSLT 

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
                xmlns:ns0="http://StudentToEmployee.Student"
>
    <xsl:output method="xml" indent="yes"/>
 
    <xsl:template match="/">
      <ns0:EmpDetails xmlns:ns0="http://StudentToEmployee.Employee">
        <sName>
          <xsl:value-of select="./StudentDetails/sName"/>
        </sName>
        <sAddress1>
          <xsl:value-of select="./StudentDetails/sAddress1"/>
        </sAddress1>
        <sAddress2>
          <xsl:value-of select="./StudentDetails/sAddress2"/>
        </sAddress2>
        <sGender>
          <xsl:value-of select="./StudentDetails/sGender"/>
        </sGender>
        <sFathersName>
          <xsl:value-of select="./StudentDetails/sFathersName"/>
        </sFathersName>
      </ns0:EmpDetails>
    </xsl:template>
</xsl:stylesheet>

Create Logic App 

1. Create a logic app and set the Integration Account which contains the Maps and Schemas. After that, take one Http Request Shape and paste the JSON schema in it.

  1. Insert "XML Validate" shape in Logic App, Set the content as @{xml(triggerBody())} and select the schema name

  1. Insert "Transform XML" shape in Logic App, Set the content as @{xml(triggerBody())} and select the map from the List.

  1. Now Insert the Response filled with 200 and body of the transformed XML.

Now your Logic app looks like below,

Your Logic App is ready and now you could consume the REST service using Chrome Postman or fiddler or SOAP UI. 

  

if you like to receive the response as JSON, then we just need to select the content as below,

Now we could see them in the Postman