Test APIs in Production
APIM provides built-in capabilities for testing in production, offering a structured way to manage API changes without disrupting active services. Specifically, revisions enable fine-grained control over API modifications. Each API version can have multiple revisions with the following states:
- Current: The active revision used for API invocations
- Online: Available for invocation, but only with explicit revision selection
(e.g.
/api/v1/resource;rev=2
). - Offline: Inactive but can be promoted to online or current status
This mechanism allows you to:
- Modify policies and configurations safely before publishing changes
- Conduct tests in production without impacting existing API consumers
- Align versioning with downstream staging services (e.g. AppService and Function App staging slots)
To use revisions, follow these steps:
- Choose an existing API group
- Create revisions for incremental modifications (e.g.
rev 2
) and policy updates, and set asOnline
- Test the revision by invoking the API under test and specifying its revision
name in the URL (e.g.
/api/v1/resource;rev=2
) - Finalize changes and promote a revision to current when ready
- Document modifications using changelogs available through APIM
As showed in the next chapter, VS Code can help you in debugging policies via its built-in debugger.
Debug APIM Policies via VS Code
Visual Studio Code can connect to an online APIM instance, and provide debugging capabilities to developers. For example, it is possible to debug a policy by using breakpoints, from the local environment. In fact, VS Code can:
- Debug policies with built-in breakpoint support
- Create API Groups using OpenAPI definitions
- Associate APIs with products
- Switch between revisions
- Execute API tests
To leverage VS Code policy-debugging capabilities:
- Install the
API Management
extension for VS Code - (Optional) Install the
REST Client
extension for VS Code: it automatically manage the subscription key in request header (Ocp-Apim-Debug
) - Run the
API Management
extension and select the APIM instance - Navigate through the desired API group and operation to debug
- Right click and select
Start Policy Debugging
- Set a breakpoint in policy body
- Invoke the API under test