Request Schema Validation in Azure API Management
For those of use that use or have implemented an Azure API Management instance, one feature that we have all looked for is a way to perform "Request Schema Validation" for incoming requests. Quite strangely, this much wanted feature is not a part of Azure API Management yet, although, there has been a User Voice request open since 2016 but the item is still marked as "Under Review". If you want to vote for this feature, you can Vote Here.
Although this feature has not been picked up by Microsoft engineers yet, this has not in any way dampened the enthusiasm around Azure API Management as an API Management tool. And as with most things, the community adapted and found workarounds to achieve what they otherwise expected out of the box.
In this blog, I will first describe the most common workaround and also the limitations that you might run into with it. Then of course, I will share how I circumvented this limitation with another workaround.
Using a Logic App
The most common and simplest approach to validating request schema is to create a http triggered logic app where you pass the request payload, download the schemas and validate the payload against the schema. A very simple 3-step process.
I am passing all parameters required to fetch the schema from API Management as headers with the HTTP request to call my Logic App. Then I form the URL to the Azure Management API to download the schemas for the API in question. Note that we also use Azure AD OAuth to authenticate our request to the Management API.
@{concat('https://management.azure.com/subscriptions/', triggerOutputs()?['headers']?['subscriptionId'], '/resourceGroups/', triggerOutputs()?['headers']?['resourceGroupId'], '/providers/Microsoft.ApiManagement/service/', triggerOutputs()?['headers']?['apimInstanceId'], '/apis/', triggerOutputs()?['headers']?['apiId'], '/schemas/', triggerOutputs()?['headers']?['schemaId'], '?api-version=2019-01-01')}
Comments
Post a Comment