Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
At a glance
Goal: Add artificial latency to API responses for testing
Time: 5 minutes
Plugins: LatencyPlugin
Prerequisites: Set up Dev Proxy
Dev Proxy allows you to simulate slow API responses by using the LatencyPlugin.
Start, by enabling the plugin in your Dev Proxy configuration file:
File: devproxyrc.json
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/rc.schema.json",
"plugins": [
{
"name": "LatencyPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "latencyPlugin"
}
],
"urlsToWatch": []
}
Next, specify the minimum and maximum delay (in milliseconds) to simulate for your API.
File: devproxyrc.json
"latencyPlugin": {
"minMs": 200,
"maxMs": 10000
}
The complete configuration file looks like this.
File: devproxyrc.json
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/rc.schema.json",
"plugins": [
{
"name": "LatencyPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
"configSection": "latencyPlugin"
}
],
"urlsToWatch": [
"https://api.example.com/*"
],
"latencyPlugin": {
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/latencyplugin.schema.json",
"minMs": 200,
"maxMs": 10000
}
}
When a response is delayed, Dev Proxy displays the total duration it was delayed for in the console output.
See also
- LatencyPlugin - Full reference
- Test my app with random errors - Simulate API failures
- Glossary - Dev Proxy terminology