Microsoft 365 Developer Proxy v0.12 with new mocking capabilities
We are excited to announce the release of Microsoft 365 Developer Proxy v0.12.0! This latest version brings a host of new features and improvements that will change the way you develop and test your applications.
Matching nth request in mocks
Have you ever needed to simulate a long running operation or test different responses for the same URL? With the new feature in v0.12.0, you can now mock the n-th call to a specific endpoint with a different response. This powerful capability allows you to accurately simulate complex scenarios without the need to tweak URLs or make manual changes. Here’s what you can do with the enhanced mock response object:
- Extend the response object with an “nth” property that accepts a number.
- The mock plugin keeps track of the number of times it matches the mock with a request.
- If “nth” is specified on the response, the mock will be applied only if the number of times it has been matched matches the number specified.
- If “nth” is not specified, the mock will be applied using the existing logic without considering the number of matched requests.
- Setting “nth” to 0 allows you to temporarily disable mocks, making it easy to switch between different mock scenarios.
Microsoft 365 Developer Proxy simulating different responses on the same API endpoint
If you’re looking for an example, check out our Microsoft Graph connector preset.
For more information about this new configuration option, see the documentation.
Create mocks from intercepted requests
Creating mocks for your intercepted requests has never been more seamless thanks to the brand-new mock generator plugin that we introduce in this version. With this new plugin, you no longer need to manually build the mocks file for your API. Instead, have the proxy generate the mocks for you automatically, based on the actual data returned by your API.
To generate mocks:
- In the configuration, enable the MockGeneratorPlugin
- Start Microsoft 365 Developer Proxy with passing all requests through to APIs (m365proxy –failure-rate 0)
- If needed, update proxy configuration on your system
- Start recording (press ‘r’ while in the terminal)
- Use your app to generate API traffic
- When ready, press ‘s’ while in the terminal
- Done: proxy has just generated for you a mock file with your mock requests
Microsoft 365 Developer Proxy generated mocks based on intercepted API requests
Delay traffic for real-world testing
Have you ever wondered how your app performs under slow network conditions or when the API that you use is overloaded? In v0.12.0, we have added a feature that allows you to “slow down” requests and emulate a slow connection and delayed API response.
Microsoft 365 Developer Proxy simulating slow API responses
This feature is perfect for demonstrating and testing your app’s performance in challenging network environments. Here’s how it works:
- Enable the new LatencyPlugin in your configuration
- Specify the minimal and maximal latency that you’d like to simulate
- Each time the proxy intercepts a request, it will slow it down with a random delay from the range you specified
For more information about the plugin, see the documentation.
Custom behavior for rate limit exceeded
Dealing with rate limits can be challenging, especially when different APIs have varying behaviors. In v0.12.0, we have extended the rate limiting plugin to support configurable behavior when the limit is exceeded. Now you can:
- Use two new configuration properties to configure the behavior when your app exceeds the API limit: “
whenLimitExceeded” and “
- Set “
whenLimitExceeded” to either “
Throttle” (default) or “
- When “
whenLimitExceeded” is set to “
Custom” provide a custom response including status, headers, and body
This flexibility ensures compatibility with APIs like GitHub, which returns a 403 Forbidden response when your app exceeds its API limits, rather than the typical 429 Too Many Requests error.
Microsoft 365 Developer Proxy simulating exceeding GitHub API rate limits
For example, see the GitHub API rate limit preset on the Sample Solution Gallery.
For more information about the new options, see the documentation.
Reset date format for rate limit
Following our work on simulating rate limits on any API, in v0.12.0, we have extended the rate limit plugin to support a configuration option for defining the format of the reset window. Now, you can choose between using the number of seconds remaining to reset (current behavior) or UTC epoch seconds, which is used by APIs like GitHub. This enhancement empowers you to work seamlessly with different rate limit implementations and use Microsoft 365 Developer Proxy with any API.
For more information about the supported configuration options, see the documentation.
Mocking Microsoft Graph batch responses
Mocking responses for Microsoft Graph batch requests just got easier! In v0.12.0, we introduce a new Graph Mock Response Plugin which supports mocking responses inside Microsoft Graph batch requests.
Microsoft 365 Developer Proxy simulating mocking requests inside a Microsoft Graph batch request
This powerful new plugin leverages the existing mock infrastructure and offers advanced capabilities to handle batch requests. Here’s what you can expect:
- Mock requests based on their URL, method, and request body inside Microsoft Graph batch requests.
- If the intercepted request is a Microsoft Graph batch request, the Graph Mock Response Plugin will unpack the batch, respond to each request with the matching mock and pack all responses into a batch
- If the intercepted request is not a batch request, it will be mocked as a regular request
Blocking unmocked requests
In v0.12.0, we have extended mock plugins with a configuration option to block passing through unmocked requests. By default, unmocked requests are passed through to the API. However, when passing through is disabled, the mock plugin will return a 502 Bad Gateway response.
Microsoft 365 Developer Proxy blocking a request that doesn’t have a matching mock response configured
This new configuration option provides more control over the behavior of your developer proxy. Now you can:
- Choose to exclusively use mocks and prevent any calls to the API.
- Ensure a consistent testing environment without worrying about accidental calls to the actual API.
- Simplify your testing workflows and reduce dependencies on external services.
Try it now
Download Microsoft 365 Developer Proxy v0.12 and check if your apps properly handle API errors.
With Microsoft 365 Developer Proxy v0.12.0, you have access to a suite of powerful features that enhance your development and testing workflows. From precise mocking capabilities to emulating real-world network conditions, we’ve got you covered. Upgrade today and build more robust apps!
Follow us on X @Microsoft365Dev to stay up to date on the latest developer news and announcements.