Mock nth request

Dev Proxy supports mocking n-th through the nth property on the request object.

Tip

Download this preset by running in the command prompt devproxy preset get microsoft-graph-connector.

Using the following mock file as an example, we can see that it contains two mocks to the same request URL. Proxy uses the first response that uses the nth property, when it intercepts a request with the specified URL for the second time. For all other requests, the proxy returns the second response.

Tip

Mocks with the nth property should be first. Proxy uses mocks based on the first match.

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.14.1/mockresponseplugin.schema.json",
  "mocks": [
    {
      "request": {
        "url": "https://graph.microsoft.com/v1.0/external/connections/*/operations/*",
        "method": "GET",
        "nth": 2
      },
      "response": {
        "statusCode": 200,
        "body": {
          "id": "1.neu.0278337E599FC8DBF5607ED12CF463E4.6410CCF8F6DB8758539FB58EB56BF8DC",
          "status": "completed",
          "error": null
        }
      }
    },
    {
      "request": {
        "url": "https://graph.microsoft.com/v1.0/external/connections/*/operations/*",
        "method": "GET"
      },
      "response": {
        "statusCode": 200,
        "body": {
          "id": "1.neu.0278337E599FC8DBF5607ED12CF463E4.6410CCF8F6DB8758539FB58EB56BF8DC",
          "status": "inprogress",
          "error": null
        }
      }
    }
  ]
}

Next step

Learn more about the MockResponsePlugin.

Samples

See also the related Dev Proxy samples: