|
| 1 | +--- |
| 2 | +name: dev-proxy |
| 3 | +description: "Simulate API failures, mock responses, test rate limiting, and analyze API traffic using Dev Proxy's plugin-based proxy engine. WHEN: 'mock API responses', 'simulate API errors', 'test rate limiting', 'test error handling', 'mock OpenAI responses', 'test AI app', 'analyze API usage', 'configure Dev Proxy', 'install Dev Proxy', 'set up Dev Proxy', 'use Dev Proxy in CI/CD', 'chaos testing for APIs', 'run Dev Proxy in background', 'detached mode', 'run Dev Proxy detached'." |
| 4 | +--- |
| 5 | + |
| 6 | +# Dev Proxy |
| 7 | + |
| 8 | +Dev Proxy is a command-line API simulator and proxy for testing how applications handle API failures, rate limits, latency, and more. It uses a plugin-based architecture configured through JSON configuration files. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +Before proceeding, verify that Dev Proxy is installed by running `devproxy --version`. If the command fails or Dev Proxy is not found: |
| 13 | + |
| 14 | +STOP — Read [references/installation.md](references/installation.md) for platform-specific installation instructions (macOS, Windows, Linux), first-run certificate setup, and verification steps. |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +Store all Dev Proxy files in `.devproxy/` in the workspace root. Start with: |
| 19 | + |
| 20 | +```bash |
| 21 | +devproxy --config-file .devproxy/devproxyrc.json |
| 22 | +``` |
| 23 | + |
| 24 | +STOP — Before creating or modifying any Dev Proxy configuration, read [references/best-practices.md](references/best-practices.md) for critical rules on file structure, plugin ordering, URL matching, and configuration patterns. |
| 25 | + |
| 26 | +## Scenario Selection |
| 27 | + |
| 28 | +Identify the user's scenario and load the corresponding reference file for detailed instructions. |
| 29 | + |
| 30 | +### Mock API Responses |
| 31 | + |
| 32 | +Return predefined responses, simulate CRUD APIs, mock MCP servers, or simulate authentication. |
| 33 | + |
| 34 | +**Plugins:** `MockResponsePlugin`, `CrudApiPlugin`, `GraphMockResponsePlugin`, `MockStdioResponsePlugin`, `AuthPlugin` |
| 35 | + |
| 36 | +STOP — Read [references/mock-api-responses.md](references/mock-api-responses.md) for mock file structure, matching rules, dynamic responses, CRUD API definitions, STDIO mocks, and auth simulation. |
| 37 | + |
| 38 | +### Test API Resilience |
| 39 | + |
| 40 | +Simulate API failures, rate limits, throttling, and slow responses to verify error handling. |
| 41 | + |
| 42 | +**Plugins:** `GenericRandomErrorPlugin`, `GraphRandomErrorPlugin`, `RateLimitingPlugin`, `RetryAfterPlugin`, `LatencyPlugin` |
| 43 | + |
| 44 | +STOP — Read [references/test-api-resilience.md](references/test-api-resilience.md) for error injection configs, rate limiting setup, throttling simulation, and latency testing. |
| 45 | + |
| 46 | +### Test LLM Applications |
| 47 | + |
| 48 | +Mock OpenAI/Azure OpenAI responses, simulate LLM failures, enforce token-based rate limits, and monitor usage. |
| 49 | + |
| 50 | +**Plugins:** `OpenAIMockResponsePlugin`, `LanguageModelFailurePlugin`, `LanguageModelRateLimitingPlugin`, `OpenAITelemetryPlugin`, `OpenAIUsageDebuggingPlugin`, `MockStdioResponsePlugin` |
| 51 | + |
| 52 | +STOP — Read [references/test-llm-apps.md](references/test-llm-apps.md) for LLM mocking with local models, failure simulation, token rate limiting, telemetry dashboards, and MCP server testing. |
| 53 | + |
| 54 | +### Analyze API Usage |
| 55 | + |
| 56 | +Record traffic and generate reports, specs, and governance insights. |
| 57 | + |
| 58 | +**Plugins:** `OpenApiSpecGeneratorPlugin`, `TypeSpecGeneratorPlugin`, `HttpFileGeneratorPlugin`, `HarGeneratorPlugin`, `ExecutionSummaryPlugin`, `UrlDiscoveryPlugin`, `MockGeneratorPlugin`, `GraphMinimalPermissionsPlugin`, `GraphMinimalPermissionsGuidancePlugin`, `ApiCenterOnboardingPlugin`, `ApiCenterProductionVersionPlugin` |
| 59 | + |
| 60 | +STOP — Read [references/analyze-api-usage.md](references/analyze-api-usage.md) for recording workflow, spec generation, permission analysis, shadow API detection, and reporting. |
| 61 | + |
| 62 | +### CI/CD Integration |
| 63 | + |
| 64 | +Automate API testing in GitHub Actions, Azure Pipelines, or any CI system. |
| 65 | + |
| 66 | +STOP — Read [references/ci-cd-integration.md](references/ci-cd-integration.md) for GitHub Actions setup, Azure Pipelines config, general CI patterns, and pipeline templates. |
| 67 | + |
| 68 | +### Configuration & Plugin Reference |
| 69 | + |
| 70 | +Set up Dev Proxy, understand plugin architecture, URL matching, proxy settings, and detached (background) mode. |
| 71 | + |
| 72 | +STOP — Read [references/configuration.md](references/configuration.md) for config file structure, plugin types and ordering, URL matching rules, proxy settings, detached mode, and process filtering. For the full plugin catalog, read [references/plugin-catalog.md](references/plugin-catalog.md). |
| 73 | + |
| 74 | +## Configuration File Structure |
| 75 | + |
| 76 | +A quick reference. All configuration details are in [references/configuration.md](references/configuration.md). |
| 77 | + |
| 78 | +```json |
| 79 | +{ |
| 80 | + "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.4.0/rc.schema.json", |
| 81 | + "plugins": [ |
| 82 | + { |
| 83 | + "name": "PluginName", |
| 84 | + "enabled": true, |
| 85 | + "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll", |
| 86 | + "configSection": "pluginConfig" |
| 87 | + } |
| 88 | + ], |
| 89 | + "urlsToWatch": ["https://api.contoso.com/*"], |
| 90 | + "pluginConfig": { |
| 91 | + "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.4.0/pluginname.schema.json" |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +### Critical Rules |
| 97 | + |
| 98 | +- Property order: `$schema` → `plugins` → `urlsToWatch` → plugin config sections → general settings |
| 99 | +- `pluginPath` is always `~appFolder/plugins/DevProxy.Plugins.dll` |
| 100 | +- Schema version must match the installed Dev Proxy version |
| 101 | +- Reporter plugins MUST be listed AFTER reporting plugins |
| 102 | +- Plugin execution order follows the config array order |
| 103 | +- File paths are relative to the config file where they are defined |
| 104 | +- Configuration hot-reloads on file save (v2.1.0+) |
| 105 | + |
| 106 | +### Plugin Ordering |
| 107 | + |
| 108 | +1. `RetryAfterPlugin` first (when simulating throttling) |
| 109 | +2. `LatencyPlugin` before mock/error plugins |
| 110 | +3. `AuthPlugin` before mock plugins |
| 111 | +4. Response-simulating plugins (mocks, errors) |
| 112 | +5. Reporting plugins |
| 113 | +6. Reporters last (`MarkdownReporter`, `JsonReporter`, `PlainTextReporter`) |
0 commit comments