{"id":15401,"date":"2023-09-27T23:43:23","date_gmt":"2023-09-28T06:43:23","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/?p=15401"},"modified":"2023-09-28T23:06:02","modified_gmt":"2023-09-29T06:06:02","slug":"microsoft-365-developer-proxy-v0-12-with-new-mocking-capabilities","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/microsoft-365-developer-proxy-v0-12-with-new-mocking-capabilities\/","title":{"rendered":"Microsoft 365 Developer Proxy v0.12 with new mocking capabilities"},"content":{"rendered":"<p>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.<\/p>\n<h2>Matching nth request in mocks<\/h2>\n<p>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&#8217;s what you can do with the enhanced mock response object:<\/p>\n<ul>\n<li>Extend the response object with an &#8220;nth&#8221; property that accepts a number.\n<img decoding=\"async\" class=\"alignnone wp-image-15402\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-1.png\" alt=\"Screenshot of code: Matching nth request in mocks\" width=\"1498\" height=\"916\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-1.png 1498w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-1-300x183.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-1-1024x626.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-1-768x470.png 768w\" sizes=\"(max-width: 1498px) 100vw, 1498px\" \/><\/li>\n<li>The mock plugin keeps track of the number of times it matches the mock with a request.<\/li>\n<li>If &#8220;nth&#8221; is specified on the response, the mock will be applied only if the number of times it has been matched matches the number specified.<\/li>\n<li>If &#8220;nth&#8221; is not specified, the mock will be applied using the existing logic without considering the number of matched requests.<\/li>\n<li>Setting &#8220;nth&#8221; to 0 allows you to temporarily disable mocks, making it easy to switch between different mock scenarios.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/00image02RS.png\"><img decoding=\"async\" class=\"aligncenter wp-image-15406 size-full\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/00image02RS.png\" alt=\"Screenshot of code: Microsoft 365 Developer Proxy simulating different responses on the same API endpoint\" width=\"1416\" height=\"1048\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/00image02RS.png 1416w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/00image02RS-300x222.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/00image02RS-1024x758.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/00image02RS-768x568.png 768w\" sizes=\"(max-width: 1416px) 100vw, 1416px\" \/><\/a><\/p>\n<p><em>Microsoft 365 Developer Proxy simulating different responses on the same API endpoint<\/em><\/p>\n<p>If you\u2019re looking for an example, check out our <a href=\"https:\/\/adoption.microsoft.com\/sample-solution-gallery\/sample\/pnp-microsoft-graph-connector\">Microsoft Graph connector preset<\/a>.<\/p>\n<p>For more information about this new configuration option, see the <a href=\"https:\/\/github.com\/microsoft\/m365-developer-proxy\/wiki\/Mock-nth-request\">documentation<\/a>.<\/p>\n<h2>Create mocks from intercepted requests<\/h2>\n<p>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.<\/p>\n<p>To generate mocks:<\/p>\n<ul>\n<li>In the configuration, enable the MockGeneratorPlugin<\/li>\n<li>Start Microsoft 365 Developer Proxy with passing all requests through to APIs (m365proxy &#8211;failure-rate 0)<\/li>\n<li>If needed, update proxy configuration on your system<\/li>\n<li>Start recording (press \u2018r\u2019 while in the terminal)<\/li>\n<li>Use your app to generate API traffic<\/li>\n<li>When ready, press \u2018s\u2019 while in the terminal<\/li>\n<li>Done: proxy has just generated for you a mock file with your mock requests<\/li>\n<\/ul>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img3_RS2.png\"><img decoding=\"async\" class=\"aligncenter wp-image-15407 size-full\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img3_RS2.png\" alt=\"Screenshot of two windows of code: Microsoft 365 Developer Proxy generated mocks based on intercepted API requests\" width=\"1362\" height=\"960\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img3_RS2.png 1362w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img3_RS2-300x211.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img3_RS2-1024x722.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img3_RS2-768x541.png 768w\" sizes=\"(max-width: 1362px) 100vw, 1362px\" \/><\/a><\/p>\n<p><em>Microsoft 365 Developer Proxy generated mocks based on intercepted API requests<\/em><\/p>\n<h2>Delay traffic for real-world testing<\/h2>\n<p>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 &#8220;slow down&#8221; requests and emulate a slow connection and delayed API response.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img4_RS.png\"><img decoding=\"async\" class=\"aligncenter wp-image-15408 size-full\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img4_RS.png\" alt=\"Screenshot of code: Microsoft 365 Developer Proxy simulating slow API responses\" width=\"1420\" height=\"1069\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img4_RS.png 1420w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img4_RS-300x226.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img4_RS-1024x771.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img4_RS-768x578.png 768w\" sizes=\"(max-width: 1420px) 100vw, 1420px\" \/><\/a><\/p>\n<p><em>Microsoft 365 Developer Proxy simulating slow API responses<\/em><\/p>\n<p>This feature is perfect for demonstrating and testing your app&#8217;s performance in challenging network environments. Here&#8217;s how it works:<\/p>\n<ul>\n<li>Enable the new LatencyPlugin in your configuration<\/li>\n<li>Specify the minimal and maximal latency that you\u2019d like to simulate<script src=\"https:\/\/gist.github.com\/waldekmastykarz\/983e479a703b6d83960295e26ef24089.js\"><\/script><\/li>\n<li>Each time the proxy intercepts a request, it will slow it down with a random delay from the range you specified<\/li>\n<\/ul>\n<p>For more information about the plugin, see the <a href=\"https:\/\/github.com\/microsoft\/m365-developer-proxy\/wiki\/LatencyPlugin\">documentation<\/a>.<\/p>\n<h2>Custom behavior for rate limit exceeded<\/h2>\n<p>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:<\/p>\n<ul>\n<li>Use two new configuration properties to configure the behavior when your app exceeds the API limit: &#8220;<code>whenLimitExceeded<\/code>&#8221; and &#8220;<code>customResponseFile<\/code>&#8220;<\/li>\n<li>Set &#8220;<code>whenLimitExceeded<\/code>&#8221; to either &#8220;<code>Throttle<\/code>&#8221; (default) or &#8220;<code>Custom<\/code>&#8220;<\/li>\n<li>When &#8220;<code>whenLimitExceeded<\/code>&#8221; is set to &#8220;<code>Custom<\/code>&#8221; provide a custom response including status, headers, and body<\/li>\n<\/ul>\n<p>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.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-15403\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-5.png\" alt=\"Screenshot of code: Microsoft 365 Developer Proxy simulating exceeding GitHub API rate limits\" width=\"1870\" height=\"1326\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-5.png 1870w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-5-300x213.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-5-1024x726.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-5-768x545.png 768w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/word-image-15401-5-1536x1089.png 1536w\" sizes=\"(max-width: 1870px) 100vw, 1870px\" \/>\n<em>Microsoft 365 Developer Proxy simulating exceeding GitHub API rate limits<\/em><\/p>\n<p>For example, see the <a href=\"https:\/\/adoption.microsoft.com\/en-us\/sample-solution-gallery\/sample\/pnp-github-rate-limiting\/\">GitHub API rate limit preset<\/a> on the Sample Solution Gallery.<\/p>\n<p>For more information about the new options, see the <a href=\"https:\/\/github.com\/microsoft\/m365-developer-proxy\/wiki\/RateLimitingPlugin\">documentation<\/a>.<\/p>\n<h2>Reset date format for rate limit<\/h2>\n<p>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.<\/p>\n<p>For more information about the supported configuration options, see the <a href=\"https:\/\/github.com\/microsoft\/m365-developer-proxy\/wiki\/RateLimitingPlugin\">documentation<\/a>.<\/p>\n<h2>Mocking Microsoft Graph batch responses<\/h2>\n<p>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.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img5_RS.png\"><img decoding=\"async\" class=\"aligncenter wp-image-15409 size-full\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img5_RS.png\" alt=\"Screenshot of code: Microsoft 365 Developer Proxy simulating mocking requests inside a Microsoft Graph batch request\" width=\"1270\" height=\"948\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img5_RS.png 1270w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img5_RS-300x224.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img5_RS-1024x764.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img5_RS-768x573.png 768w\" sizes=\"(max-width: 1270px) 100vw, 1270px\" \/><\/a><\/p>\n<p><em>Microsoft 365 Developer Proxy simulating mocking requests inside a Microsoft Graph batch request<\/em><\/p>\n<p>This powerful new plugin leverages the existing mock infrastructure and offers advanced capabilities to handle batch requests. Here&#8217;s what you can expect:<\/p>\n<ul>\n<li>Mock requests based on their URL, method, and request body inside Microsoft Graph batch requests.<\/li>\n<li>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<\/li>\n<li>If the intercepted request is not a batch request, it will be mocked as a regular request<\/li>\n<\/ul>\n<h2>Blocking unmocked requests<\/h2>\n<p>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.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img6_RS.png\"><img decoding=\"async\" class=\"aligncenter wp-image-15410 size-full\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img6_RS.png\" alt=\"Screenshot of code: Microsoft 365 Developer Proxy blocking a request that doesn\u2019t have a matching mock response configured\" width=\"1441\" height=\"1081\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img6_RS.png 1441w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img6_RS-300x225.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img6_RS-1024x768.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/09\/img6_RS-768x576.png 768w\" sizes=\"(max-width: 1441px) 100vw, 1441px\" \/><\/a><\/p>\n<p><em>Microsoft 365 Developer Proxy blocking a request that doesn\u2019t have a matching mock response configured<\/em><\/p>\n<p>This new configuration option provides more control over the behavior of your developer proxy. Now you can:<\/p>\n<ul>\n<li>Choose to exclusively use mocks and prevent any calls to the API.<\/li>\n<li>Ensure a consistent testing environment without worrying about accidental calls to the actual API.<\/li>\n<li>Simplify your testing workflows and reduce dependencies on external services.<\/li>\n<\/ul>\n<h2>Try it now<\/h2>\n<p><a href=\"https:\/\/aka.ms\/m365\/proxy\/download\">Download Microsoft 365 Developer Proxy v0.12<\/a> and check if your apps properly handle API errors.<\/p>\n<p>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&#8217;ve got you covered. Upgrade today and build more robust apps!<\/p>\n<p>Follow us on X\u00a0<a href=\"https:\/\/twitter.com\/Microsoft365Dev\">@Microsoft365Dev<\/a> to stay up to date on the latest developer news and announcements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft 365 Developer Proxy v0.12 features new mocking capabilities to help develop and test your applications.<\/p>\n","protected":false},"author":74222,"featured_media":15413,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,3],"tags":[222],"class_list":["post-15401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-365-developer","category-microsoft-graph","tag-developer-proxy"],"acf":[],"blog_post_summary":"<p>Microsoft 365 Developer Proxy v0.12 features new mocking capabilities to help develop and test your applications.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/15401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/74222"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=15401"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/15401\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/15413"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=15401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=15401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=15401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}