Skip to content

Code generation

The Code button in the URL bar opens a dialog that turns the current draft into client code. Four languages are supported, and the snippet updates live as you edit the request.

The four languages

LanguageWhen to use it
cURLRun from a terminal, paste into documentation, or use as a quick sanity check.
JavaScript fetchDrop into a browser script or a Node.js application.
Python requestsDrop into a Python script or a notebook.
Bun fetchDrop into a Bun script (slight ergonomic differences from fetch in browsers/Node).

The language is selected with a dropdown at the top of the dialog. The snippet below the dropdown is read-only and updates as you change the request.

A Copy button next to the language dropdown puts the snippet on the clipboard.

How variables are handled

The generated snippet uses the resolved URL, headers, and body — i.e. the values that were substituted from the active environment. So if your URL is {{baseUrl}}/users/{{userId}} and your environment has baseUrl=https://api.example.com and userId=42, the cURL snippet will already show https://api.example.com/users/42.

This is by design: the snippet is meant to be copy-pasted into a context where the {{baseUrl}} variable doesn't exist. The original request, of course, still stores the unresolved form.

What the snippet includes

  • The method and the fully resolved URL, including any query parameters
  • Every enabled header
  • Any Authorization header implied by the chosen Auth mode
  • The body, where it makes sense:
    • Raw body: inlined as a string
    • URL-encoded body: serialized with URLSearchParams (in JS) or requests's data= (in Python)
    • Multipart and Binary bodies: replaced with a <binary or multipart body> placeholder. The snippet does not include the file bytes.

Things to know about each language

cURL

bash
curl --request GET 'https://api.example.com/users/42' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <token>'

The basic-auth username/password are not encoded into the snippet; instead, the snippet shows Authorization: Basic <base64(<username>:password)> as a literal placeholder. Replace the angle-bracket text with a real base64 string before running it.

JavaScript fetch

js
fetch("https://api.example.com/users/42", {
  method: "GET",
  headers: {
    "Accept": "application/json",
    "Authorization": "Bearer <token>"
  }
})
  .then(async (response) => console.log(response.status, await response.text()));

await response.text() is the default; if you want JSON, replace it with await response.json(). The snippet is browser-shaped; it also works in Node 18+ and Bun without changes.

Python requests

python
import requests

response = requests.request(
    "GET",
    "https://api.example.com/users/42",
    headers={
        "Accept": "application/json",
        "Authorization": "Bearer <token>"
    },
)

print(response.status_code)
print(response.text)

For JSON bodies the snippet uses data=; for urlencoded bodies it uses data= with a string.

Bun fetch

js
const response = await fetch("https://api.example.com/users/42", {
  method: "GET",
  headers: {
    "Accept": "application/json",
    "Authorization": "Bearer <token>"
  }
});

console.log(response.status, await response.text());

The only difference from the JavaScript version is that the await is at the top level and the .then chain is removed. If you use the snippet in a non-Bun context, wrap it in an async function.

Limitations

  • The dialog only generates one language at a time. There's no "copy as cURL and Python" batch action.
  • The snippet is read-only. Editing it doesn't edit the request.
  • Multipart file bodies and binary bodies are placeholder strings. The snippet cannot include file contents; copy the request into your own code if you need to send files programmatically.

What's next?

Released under the MIT License.