Reverse Engineer an API
Reverse engineering an API involves generating Swagger API documentation when documentation is not available. One way to do this is by using mitmwebproxy to intercept and capture the traffic of the API. The traffic can then be exported in flow file format and used as input for mitmproxy2swagger, a python CLI tool. This tool converts the flow file's HTTP requests into API documentation in the form of a Swagger file, allowing developers and testers to understand and utilize the API's endpoints, parameters, and responses.
First, set up the Man In The Middle (MITM) web proxy. This can be done by installing a tool such as MITMwebproxy.
Next, open Firefox and configure the MITM proxy using an addon such as FoxyProxy. This will ensure that all traffic from Firefox is intercepted by the MITM web proxy.
Perform the functional activity on your API through the user interface.
Certain APIs that you want to document will be logged on the MITM web proxy.
Export those APIs in flow file format, which is the inbuilt file format of MITM.
Install mitmproxy2swagger, a tool that can convert mitmproxy flow files into Swagger documentation.
Execute the tool, providing the flow file as input and setting a .yml file as output. Command:
The generated .yml files may have errors, so it's necessary to fix those first.
After fixing the errors, re-execute the command and add -examples in the command.
Open the Swagger online editor (https://editor.swagger.io/)
Import the .yml file
The documentation is ready for use.
Last updated