Inspect traffic
Copy as code
Copy any captured request as cURL, Python, JavaScript, Swift, Go, a k6 load test, a Playwright test and more, 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 24 formats: cURL, 21 other languages, libraries and test tools, a Markdown summary, and a .http file.
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 the copy button at the right of the format menu.
The tab remembers the format you chose.
- Select a request.
- Click the ••• menu at the right of the inspector’s summary 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.
A request paused at a breakpoint has its own Copy menu, which copies it with your edits. See Copy the paused request.
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 |
| k6 – load test Since 0.2.0 | A k6 script that sends the request with 10 virtual users for 30 seconds (options = { vus: 10, duration: '30s' }), checks for a 2xx status and sleeps a second between iterations. Run it with k6 run. |
| Python – httpx Since 0.2.0 | The httpx library. JSON bodies become a Python dictionary passed as json=; other text bodies go in content=. |
| Playwright – API test Since 0.2.0 | A @playwright/test test named after the method and path that sends the request with request.fetch and expects response.ok(). JSON bodies go in data. |
| 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. |
| .http (REST Client) | A .http request for VS Code’s REST Client, JetBrains HTTP Client or Cloak Proxy’s own .http files: a ### title, the request line, the headers (without Host and Content-Length) and the body, decompressed. |
The language snippets print the response when they run; most print the status code and the body. The k6 and Playwright snippets check the status instead.
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))import http from 'k6/http';import { check, sleep } from 'k6';
export const options = { vus: 10, duration: '30s' };
export default function () { const headers = { "Content-Type": "application/json", "Authorization": "Bearer sk_test_xxxx", }; const res = http.request("POST", "https://api.example.com/v1/orders", "{\"sku\":\"A1\",\"qty\":2}", { headers }); check(res, { 'status is 2xx': (r) => r.status >= 200 && r.status < 300 }); sleep(1);}### 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. --compressed is added when the request has Accept-Encoding. |
All, in a table | All except Host, Content-Length, Connection, Proxy-Connection and Accept-Encoding |
| Text body | As --data-raw '…', so a body that starts with @ is never read as a file |
In a code block, indented if it’s JSON | In the language’s own form |
| Binary body | Printed by printf and piped in with --data-binary @-, so the command needs no extra file |
Left out | Left out |
| Compressed request body | The captured bytes, piped in like a binary body | 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.
To get type definitions for a JSON response or request body instead of code that sends the request, right-click the request and choose Generate Types from Response… or Generate Types from Request Body…. See Generate types.