Edit

Share via


Plugin architecture

A plugin is a .NET class registered with Dev Proxy that introduces a specific Dev Proxy behavior. A plugin can offer real-time guidance about API usage, simulate API behavior, analyze multiple API requests, or produce a report. Dev Proxy has three types of plugins:

  • intercepting plugins that intercept requests and responses and can analyze and modify them
  • reporting plugins that run on requests recorded by Dev Proxy
  • reporters that generate reports based on the data collected by reporting plugins

You register plugins in the devproxyrc.json file. The file contains a list of plugins to load and their configuration.

Dev Proxy comes with a collection of plugins and you can create custom plugins to extend Dev Proxy functionality to match your needs.

When Dev Proxy starts, it loads plugins enabled in its configuration file. Depending which plugins you enable, Dev Proxy can provide guidance, simulate API behavior, or analyze API requests. Following sections explain how the different types of plugins work.

Intercepting plugins

When Dev Proxy intercepts a request matching one of the URLs in the urlsToWatch array, it invokes each intercepting plugin in the order they're listed in the configuration file. Each intercepting plugin inherits from the BaseProxyPlugin class, and can subscribe to the following events:

  • BeforeRequest - raised when Dev Proxy intercepts a request
  • BeforeResponse - raised after Dev Proxy receives a response from the server
  • AfterResponse - raised after Dev Proxy sends the response to the client

For each of these events, plugins can define an event handler. In the handler, the plugin can analyze the request and response, and modify it if needed. It can also output guidance messages. To see what's possible, see the code of plugins provided with Dev Proxy.

Reporting plugins

Dev Proxy allows you to record API requests and responses. You typically use recording to report on API usage or analyze multiple API requests. Reporting plugins inherit from the BaseReportingPlugin class, and register an event handler with the AfterRecordingStop event.

When you stop recording, Dev Proxy raises the AfterRecordingStop event, passing the list of recorded requests and responses as an argument to the registered event handlers. Reporting plugins can then analyze the recorded data and generate a report object. A report object is an arbitrary object defined by the reporting plugin. Reporting plugins store the reports by calling the StoreReport method.

Important

Reporting plugins generate report objects, which Dev Proxy stores in memory. To convert these report objects into user-readable reports, you must enable one or more reporters in the Dev Proxy configuration file.

Reporters

Dev Proxy uses reporters to convert report objects generated by reporting plugins into user-readable reports. For example, the MarkdownReporter converts a report object into a Markdown file. Reporters are special plugins that inherit from the BaseReporter class. They implement the GetReport method, which takes as argument a report created by a reporting plugin and converts it into a string. This string is then saved on disk following the PluginName_ReporterName.ReporterExtension pattern, for example: ApiCenterOnboardingPlugin_MarkdownReporter.md.

Important

Because reporters depend on the report objects generated by reporting plugins, you must enable the reporting plugins in the Dev Proxy configuration file after reporting plugins. If you enable them before reporting plugins, reporters won't have any data to report on.