Generate Code and Export API Documentation
This article shows how to turn captured requests into artifacts: convert a single request into runnable code with one click (cURL / Python / JavaScript / Go / OkHttp), automatically merge an entire session into standard API documentation (OpenAPI), or export it to the universal HAR format; session files captured elsewhere can also be imported for further analysis. No manual copying or writing—everything comes directly from real packet captures.
1. When to Use It
Use it if any of the following applies:
- You want to reproduce a real captured request in a script / project, or send it to a colleague (anyone can run a cURL command).
- You have a working request in the request builder and want to export it as code to continue development.
- You have captured a segment of API traffic and need a deliverable, importable OpenAPI API document—for third-party integration, supplementing backend docs, or generating test cases.
- You want to export this packet capture in a universal format (HAR) for delivery, archiving, or handing off to another tool.
- You have session files captured by someone else / in production / by another tool and want to bring them in to continue analysis using decoding, host profiles, and request diff here.
2. Prerequisites
- TraceEagle is installed and running.
- To generate code / export OpenAPI / export HAR: first capture requests (any capture method works; see Quick Start. As long as there is data in the request list, you can proceed.
- For 'Import External Session' only: no need to capture packets first; just have the corresponding session file.
3. Step-by-Step Operations
A. Generate Code for a Single Request and Copy It
- In the request list, select a request you want to reproduce or share.
- Right-click → 'Generate Code…'. (You can also configure a request in Request Construction and Replay, then click 'Generate Code'; the export method is the same.)
- At the top, switch language to regenerate instantly; there are 5 formats in total:
- cURL (paste into a terminal and run)
- Python
- JavaScript
- Go
- OkHttp (Java / Kotlin)
- Click Copy, then paste it into a terminal / project / send it to a colleague.
The generated code is complete: request method, URL, all request headers, and request body are included; request headers also keep their original order and duplicates are allowed, preserved exactly as-is, so the result matches the real request when run.
Common tools often reorder and deduplicate request headers when generating code, which makes reproduction inaccurate; here they are preserved as-is for more faithful reproduction.
B. Export an Entire Session to OpenAPI / HAR
Export OpenAPI (API Documentation)
- After capturing a segment of API traffic, open Export API Documentation (OpenAPI).
- It analyzes first, then exports: it automatically identifies APIs from the current session and lists them for you to select. The list directly shows each API's method, path, occurrence count, and observed status codes, giving you a clear overview.
-
Select the APIs you want (only selected ones are exported, avoiding noise). The tool automatically helps you:
-
Merge paths: templatize paths containing specific IDs, e.g.
/users/123→/users/{id}, merging multiple requests to the same API into one entry. - Infer structure: merge request / response JSON structures, group responses by status code, and organize path variables into parameters.
-
Merge paths: templatize paths containing specific IDs, e.g.
- On the right, preview in real time the generated standard OpenAPI 3.0 document. Once confirmed, click Copy or Download and import it into any OpenAPI-supported API tool to continue working.
Export HAR (Universal Exchange Format)
- On the session, select Export HAR.
- The entire packet capture is exported with one click as a standard HAR 1.2 file for delivery, archiving, or handing off to another tool for further analysis.
C. Import External Sessions
- Select Import Session.
- Select the file to import—HAR 1.2,
.pcap/.pcapng, and session files exported by common packet capture tools are supported. - After import, packets captured by others appear in the request list, and you can continue viewing, comparing, and exporting as usual, as well as continue analysis with decoding and host profiles here.
4. Verification: Confirm You Have the Artifacts
- Generate Code: the preview refreshes instantly when switching languages; if the cURL command runs successfully in a terminal and returns the same result as captured, it means request headers / body were fully included.
-
Export OpenAPI: after selecting APIs, the right-side preview shows methods, paths (already templatized as
/{id}), parameters, and response structures; the copied / downloaded result is an OpenAPI 3.0 document that API tools can import. -
Export HAR / Import Session: after export you get a
.harfile; after importing an external file, corresponding request entries appear in the request list, and clicking one shows full details.
5. Tips and Troubleshooting
| Symptom | Likely Cause | What to Do |
|---|---|---|
| Generated code does not match the real request when run | Request header order was manually changed, or a header was missed | Regenerate code from the original request; header order and duplicates are preserved by default, so no manual fixing is needed |
| Desired language is not available | Currently five formats are provided: cURL / Python / JavaScript / Go / OkHttp | Export the closest one first (e.g. cURL), then convert as needed |
| Unrelated APIs appear in the OpenAPI list | The session contains noise traffic | In the 'analyze first, then export' list, check only the APIs you want; unselected ones are not exported |
| The same API is split into multiple entries | Paths contain specific IDs and were not merged | Merging templatizes paths like /users/123 into /users/{id}; if they are still separate, confirm their methods / path structures are consistent |
| Want to analyze packets captured in production / by a colleague | Data is not in the local session | Use 'Import Session' to bring in HAR 1.2 / .pcap / .pcapng files; after import, view, compare, and export as usual |
| Want to hand off to another tool that does not recognize this tool's format | A universal exchange format is needed | Export HAR 1.2 (for delivery, archiving, cross-tool use) or OpenAPI 3.0 (universal API documentation) |
- Before generating code, inspect the request clearly, switch views, and decode it: see Data Viewing and Decoding
- To fine-tune a request before exporting it as code, or modify and resend it: see Request Construction and Replay.
- To compare an imported session line by line with the local one: see Request Diff.
- For private / in-house protocols, if you want the tool to understand them before export: see Custom Protocol Decoding.
Top comments (0)