Friday Fact: Did you know that Azure API Management supports Schemas

  • Fernando Nunes
  • Aug 1, 2025
  • 4 min read

Azure API Management (APIM) not only helps manage APIs but also supports Schemas to enhance the usability of APIs. By utilizing Schemas, developers can define the structure of the data being sent and received, ensuring consistency and clarity. This feature allows for better validation, error handling, and improved communication between services. With Schemas, you can streamline your API design process and provide a better experience for your API consumers.

What are message Schemas (XML & JSON)?

In messaging systems (whether they involve API communication, data interchange, or service integrations), schemas define the expected structure and rules of the data being sent or received. These schemas ensure that the data adheres to a predefined format and that both the sender and the receiver of the message agree on the structure of the message.

  • XML Schema (XSD): An XML Schema Definition (XSD) is used to define the structure and data types for XML messages. It specifies the allowed elements, their attributes, and the relationships between them within an XML document. XSD ensures that XML messages are consistent, valid, and adhere to the rules defined by the schema.
    • Key Features of XML Schema:
      • Elements and Attributes: Defines the allowed XML elements and attributes.
      • Data Types: Specifies the data types for the elements (e.g., string, integer, date).
      • Validation: Ensures the XML content matches the required structure.
  • JSON Schema: A JSON Schema serves a similar purpose to XML Schema (XSD) but is used for validating the structure of JSON messages. JSON Schema defines the expected properties, data types, and constraints for the JSON data, ensuring that the data conforms to the required structure.
    • Key Features of JSON Schema:
      • Properties: Defines what keys (fields) are expected in the JSON object.
      • Data Types: Specifies the type of data for each property (e.g., string, number, boolean).
      • Constraints: Can enforce conditions such as minimum or maximum values, regex patterns, or required fields.
      • Validation: Used to validate the JSON message against the schema to ensure it meets the required structure.

Why are Schemas so important in Messaging?

  • Data Validation:
    • Both XML Schema and JSON Schema are used to validate incoming messages, ensuring they conform to the expected structure and preventing errors or invalid data from being processed.
  • Consistency:
    • Schemas ensure that the data format is consistent across different systems or services. This is especially critical in integrations where multiple applications or services need to communicate using a shared message format.
  • Documentation:
    • Schemas act as a contract between systems. They provide clear documentation for developers on the structure and types of data expected in the messages.
  • Interoperability:
    • By using schemas, different systems, whether they use XML or JSON, can interact smoothly, knowing exactly how the data should be structured and ensuring proper processing.
  • Security:
    • Validation through schemas ensures that the data received is well-formed and matches the expected structure, reducing the risk of malicious data or injection attacks.

How to Upload Schemas to API Management?

  • Access the Azure Portal:
    • Go to the Azure portal and navigate to your API Management instance.
  • Navigate to Schemas:
    • In the left-hand menu, under the API section, click on Schemas.
  • Add a New Schema:
    • Click on the + Add schema button to upload your schema file. You can define the schema in JSON or XML formats.

How to use Schemas in API Management Policies?

  • Access Policies:
    • Select the API to which you want to apply the schema, and then click the Design tab, followed by Policies.
  • Add a Validation Policy:
    • In the policy editor, you can use the <validate-content> policy to reference your uploaded schema for request/response validation.
    • Here is an example of this policy:
<inbound>
        <base />
        <validate-content unspecified-content-type-action="prevent" max-size="1000000" size-exceeded-action="prevent" errors-variable-name="validationErrors">
            <content type="application/json" validate-as="json" action="prevent" schema-id="ProductSchema" allow-additional-properties="true" case-insensitive-property-names="true" />
        </validate-content>
        <json-to-xml apply="always" consider-accept-header="false" />
 </inbound>

Hope you have enjoyed this Friday Fact and we will se you in the next one!

To lazy to read? We’ve got you covered! Check out our video version of this content!

Hope you find this helpful! If you enjoyed the content or found it useful and wish to support our efforts to create more, you can contribute towards purchasing a Star Wars lego for Sandro’s son, yep, not for me!

Leave a Reply

Your email address will not be published. Required fields are marked *

The Ultimate Cloud
Management Platform for Azure

Supercharge your Azure Cost Saving

Learn More
Turbo360 Widget

Back to Top