Inspect traffic
Copy as code
Copy any captured request from Cloak Proxy as cURL, Python, JavaScript, Swift, Go and 14 more languages, or as a Markdown summary, ready to run or share.
Copy as code turns a captured request into a command or code snippet that sends the same request: same method, URL, headers and body. Use it to reproduce a bug from the terminal, hand a failing call to a teammate, or start a script from what your app really sent. There are 20 formats: cURL, 18 other languages and libraries, and a Markdown summary.
Copy a request as code
Section titled “Copy a request as code”There are four ways, depending on where you are.
- Right-click a request in the traffic list.
- Choose Copy as cURL, or choose Copy as › and pick a format.
With several requests selected, you get one snippet per request, separated by a blank line.
-
Select a request and open the Code tab in the request pane.
-
Choose a format from the menu.
The code appears below, so you can read it before copying.
-
Click Copy.
The tab remembers the format you chose.
- Select a request.
- Click the ••• menu at the right of the inspector’s header bar and choose Copy as cURL.
- Select one or more requests.
- Press ⇧ ⌘ A and type
copy asand a format, for examplecopy as go. - Press Return.
The Code tab shows the snippet before you copy it.
- Choose a format
- Copy to the clipboard
Encrypted tunnels have no request to copy and are skipped.
Formats
Section titled “Formats”| Menu name | Produces |
|---|---|
| cURL | A curl command, one option per line |
| Swift | URLRequest and URLSession.shared.data(for:) with async/await |
| JavaScript | fetch with await. JSON bodies are passed through JSON.stringify. |
| Python | The requests library. JSON bodies become a Python dictionary passed as json=. |
| Go | net/http with http.NewRequest |
| HTTPie | An http command. A body is piped in with echo. |
| Shell – wget | A wget command that prints the response |
| HTTP | The raw HTTP/1.1 request, with Host and Content-Length |
| NodeJS – Axios | axios.request |
| Python – http.client | The standard library’s http.client |
| Java – OkHttp | OkHttp’s Request.Builder |
| Kotlin – OkHttp | OkHttp with Kotlin extensions (toMediaType, toRequestBody) |
| C# – HttpClient | HttpClient and HttpRequestMessage |
| PHP – cURL | curl_setopt_array |
| Ruby – Net::HTTP | Net::HTTP, with use_ssl for HTTPS |
| Rust – reqwest | reqwest::Client in a tokio main function |
| Dart – http | The http package’s http.Request |
| PowerShell | Invoke-RestMethod with a headers dictionary |
| C – libcurl | A small C program using curl_easy |
| Markdown | A heading with the method and URL, a table of headers and the body in a code block. For bug reports and docs, not for running. |
The language snippets print the response when they run; most print the status code and the body.
Example
Section titled “Example”A POST to https://api.example.com/v1/orders with a JSON body and a bearer token comes out like this:
curl \ -X POST \ 'https://api.example.com/v1/orders' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer sk_test_xxxx' \ --data-binary '{"sku":"A1","qty":2}'import requests
headers = { "Content-Type": "application/json", "Authorization": "Bearer sk_test_xxxx",}payload = { "sku": "A1", "qty": 2}response = requests.request("POST", "https://api.example.com/v1/orders", headers=headers, json=payload)print(response.status_code, response.text)const response = await fetch("https://api.example.com/v1/orders", { method: "POST", headers: { "Content-Type": "application/json", "Authorization": "Bearer sk_test_xxxx" }, body: JSON.stringify({"sku":"A1","qty":2})});console.log(response.status, await response.text());import Foundation
var request = URLRequest(url: URL(string: "https://api.example.com/v1/orders")!)request.httpMethod = "POST"request.setValue("application/json", forHTTPHeaderField: "Content-Type")request.setValue("Bearer sk_test_xxxx", forHTTPHeaderField: "Authorization")request.httpBody = Data("""{"sku":"A1","qty":2}""".utf8)
let (data, response) = try await URLSession.shared.data(for: request)print((response as? HTTPURLResponse)?.statusCode ?? 0)print(String(decoding: data, as: UTF8.self))### POST https://api.example.com/v1/orders
**Headers**
| Name | Value ||---|---|| Host | api.example.com || Content-Type | application/json || Authorization | Bearer sk_test_xxxx || Content-Length | 20 |
**Body**
```{ "sku": "A1", "qty": 2}```What’s included and what’s left out
Section titled “What’s included and what’s left out”| cURL | Markdown | Every other format | |
|---|---|---|---|
| Method and URL | Yes. -X is added unless it’s a GET without a body. |
Yes, in the heading | Yes |
| Headers | All except Content-Length, Connection and Proxy-Connection. Host only when it differs from the URL’s host. |
All, in a table | All except Host, Content-Length, Connection, Proxy-Connection and Accept-Encoding |
| Text body | As --data-binary '…' |
In a code block, indented if it’s JSON | In the language’s own form |
| Binary body | As --data-binary @request-body.bin, for you to supply the file |
Left out | Left out |
| Compressed request body | The captured bytes, so usually @request-body.bin, and --compressed is added |
Decompressed | Decompressed. The Content-Encoding header is still included, so remove it before running. |
Run a copied request through Cloak Proxy
Section titled “Run a copied request through Cloak Proxy”A copied snippet talks to the server directly, so its traffic doesn’t appear in Cloak Proxy unless the program uses the proxy. To see it, run it from a terminal that’s set up for Cloak Proxy (see Terminal and runtimes), or resend the request from inside the app with Repeat or Edit and Repeat.
To keep a request and work on it, save it to the API client, which has its own code snippets.