3
votes

How can I apply validation that all request parameters in body are required for my post request? What policy expressions I may use? I am using following expression:

<policies>
<inbound>
    <base />
    <choose>
        <when condition="@((context.Request.Body) != null&& ((int)context.Request.Body.As<JObject>()["Id"])>0)">
            <return-response>
            </return-response>
        </when>
        <otherwise>
            <return-response>
            </return-response>
        </otherwise>
    </choose>
</inbound>

How can I restrict to input all body parameters for this post request?

1

1 Answers

3
votes

See APIM's content validation policies: https://docs.microsoft.com/en-us/azure/api-management/validation-policies#validate-content They allow you to validate that request actually conforms to the schema specified in your spec.

As an alternative you could read body as JObject and manually checking each property of interest. Mind that you want to use context.Request.Body.As(preserveContent: true) to ensure that body is cached and available to later be sent to backend.