Edit

Share via


Generate an HTTP file

Dev Proxy allows you to generate an HTTP file from intercepted API requests and responses. Using HTTP files is especially useful for developers who want to simulate API behavior or share reproducible API interactions. The HTTP file includes all relevant request and response details, with sensitive information replaced by variables for security and reusability.

To generate an HTTP file using Dev Proxy:

  1. In the configuration file, enable the HttpFileGeneratorPlugin:

    {
      "plugins": [
        {
          "name": "HttpFileGeneratorPlugin",
          "enabled": true,
          "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
          "configSection": "httpFileGeneratorPlugin"
        }
      ]
      // [...] shortened for brevity
    }
    
  2. Optionally, configure the plugin:

    {
      "httpFileGeneratorPlugin": {
        "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.2/httpfilegeneratorplugin.schema.json",
        "includeOptionsRequests": false
      }
      // [...] shortened for brevity
    }
    
    • includeOptionsRequests: Determines whether to include OPTIONS requests in the generated HTTP file. Default is false.
  3. In the configuration file, to the list of URLs to watch, add the URL of the API for which you want to generate an HTTP file:

    {
      "urlsToWatch": [
        "https://api.example.com/*"
      ]
      // [...] shortened for brevity
    }
    
  4. Start Dev Proxy:

    devproxy
    
  5. Start recording requests by pressing r.

  6. Perform the API requests you want to include in the HTTP file.

  7. Stop recording by pressing s.

  8. Dev Proxy generates an HTTP file and saves it in the current directory. The file includes all captured requests and responses, with sensitive data like bearer tokens and API keys replaced by variables. For example:

    @jsonplaceholder_typicode_com_api_key = api-key
    ###
    # @name getPosts
    GET https://jsonplaceholder.typicode.com/posts?api-key={{jsonplaceholder_typicode_com_api_key}}
    Host: jsonplaceholder.typicode.com
    User-Agent: curl/8.6.0
    Accept: */*
    Via: 1.1 dev-proxy/0.29.0
    

    The plugin automatically creates variables for each combination of hostname and sensitive parameter, reusing them across requests when applicable.

Screenshot of two command prompt windows. One shows Dev Proxy recording API requests. The other shows the generated HTTP file.

Next steps

Learn more about the HttpFileGeneratorPlugin.