Skip to content

Code & Type Generation

recon export code turns a saved request into a ready-to-paste client snippet, with secret values replaced by placeholders. recon export types reads a recorded response from the Flight Recorder and generates typed models for it. Use them to hand a working call to a teammate or to start client code without typing out headers and fields.

Terminal window
recon export code "Create Enrollment" --lang curl
curl -X POST 'http://127.0.0.1:8787/_sandbox/local/v1/enrollments' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer ${DEV_API_TOKEN}' \
-d '{
"student_id": "001001",
"course": "CS-401"
}'

DEV_API_TOKEN is a secret in the demo local environment, so its value is replaced by ${DEV_API_TOKEN}.

recon export code [OPTIONS] <REQUEST>
Argument or flag Default Meaning
<REQUEST> required Saved request ID or name (name compared case-insensitively).
--lang <LANG> curl Target language. See the table below. Case-insensitive.
--env <ENV> default_env Environment used to resolve {{variables}}.

The snippet is printed to stdout as plain text. --format does not change it.

--lang (aliases) Output
curl A curl -X <METHOD> '<url>' command with one -H per header and -d for the body. Single quotes in the body are escaped for the shell.
httpie (http) An HTTPie http <METHOD> '<url>' command with 'Name:value' header items. A body is piped in with printf '%s' '<body>' |.
fetch (js, javascript, ts) const res = await fetch(url, { method, headers, body }); followed by console.log(res.status, await res.text());.
httpx (python, py) import httpx and httpx.request(method, url, headers=..., content=...), then print(res.status_code, res.text).
go (golang) A net/http fragment: http.NewRequest, req.Header.Set per header, http.DefaultClient.Do(req). No package or import lines. The body uses strings.NewReader.
reqwest (rust) A reqwest::Client builder chain with .header(...), .body(...), .send().await?.
mo A Mo Http.request(method, url) chain with .header(...) and .body("...".bytes), then req.send()?!.
hurl A Hurl entry: request line, header lines, the body text directly after the headers, then HTTP 200. The status line is always HTTP 200, whatever your assertions say.
csharp (cs, c#) HttpClient with an HttpRequestMessage, TryAddWithoutValidation per header, StringContent for the body.
ruby (rb) Net::HTTP::GenericRequest with req["Name"] = value per header, req.body, and Net::HTTP.start.

The same request in two other languages:

Terminal window
recon export code "Create Enrollment" --lang httpx
import httpx
res = httpx.request(
"POST",
"http://127.0.0.1:8787/_sandbox/local/v1/enrollments",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer ${DEV_API_TOKEN}",
},
content="{\n \"student_id\": \"001001\",\n \"course\": \"CS-401\"\n}",
)
print(res.status_code, res.text)
Terminal window
recon export code "Create Enrollment" --lang hurl
POST http://127.0.0.1:8787/_sandbox/local/v1/enrollments
Content-Type: application/json
Authorization: Bearer ${DEV_API_TOKEN}
{
"student_id": "001001",
"course": "CS-401"
}
HTTP 200

Recon resolves the request the same way it does before sending, then renders the result:

  • The URL with every {{variable}} resolved and query parameters appended.
  • The request headers, plus headers from bearer, basic and api_key auth (an api_key in query location is appended to the URL).
  • A Content-Type header when the request has none: application/json, text/plain; charset=utf-8, application/x-www-form-urlencoded, or multipart/form-data; boundary=... with a fresh random boundary.
  • The body as text. URL-encoded forms appear encoded (user=ada+lovelace). Multipart bodies appear in full when they are valid UTF-8. Binary (Base64) bodies are left out of the snippet; only the application/octet-stream header remains.

Some parts of a request are not in the snippet:

  • Pre-request scripts are not run, so headers or variables they would set are missing.
  • oauth2, aws_sigv4 and hmac auth are not applied. There is no Authorization or signature header for them.
  • Secret URIs such as age:// and op:// are not resolved.
  • Timeouts, redirect settings and assertions are not included.
  • The Outbound Secret Firewall does not run.

A placeholder that does not resolve stays as {{NAME}} in the snippet. If the URL is still a placeholder, export fails with invalid URL.

Before rendering, Recon replaces every tracked secret value with ${LABEL}:

  • Secrets are environment variables defined with secret = true, and {{$env.NAME}} values. The label is the variable’s label, or its name if there is none. See Configuration.
  • Both the raw value and its Base64 form are replaced. For basic auth, the Base64 form covers username:password, so the whole credential becomes ${LABEL}.

With a secret password labelled ADA_PW:

curl -X GET 'https://example.com/b' \
-H 'Authorization: Basic ${ADA_PW}'

With the same password stored as a plain variable, nothing is masked:

http GET 'https://example.com/b' \
'Authorization:Basic YWRhOmh1bnRlcjI='

Errors are reported as E_CLI_RUNTIME with exit status 2.

Message Cause
request `nope` not found No request has that ID or name.
parse error in `codegen`: unsupported codegen language `java` Unknown --lang. The request is resolved first, so a resolution error can appear before this one.
invalid URL `{{base_url}}/v1/students`: relative URL without a base: ... The environment does not define a variable the URL needs, or --env names an environment that does not exist.

recon export types reads the response body of a recorded run and prints model definitions for it. Get a run ID from the run_id field of recon --format json send ... or from the first column of recon history.

Terminal window
recon export types 01a22d21-6238-7380-a5fd-12470d865dbd --lang ts --name StudentList
export interface StudentList {
environment: string;
request_id: string;
session_token: string;
students: StudentListStudentsItem[];
}
export interface StudentListStudentsItem {
email: string;
full_name: string;
gpa: number;
notes: string;
phone: string;
program: string;
ssn: string;
student_id: string;
}

The stored response body is used as recorded. The output contains field names and types only, never values.

recon export types [OPTIONS] <RUN_ID>
Argument or flag Default Meaning
<RUN_ID> required Flight Recorder run ID.
--lang <LANG> ts Target. See the table below. Case-insensitive.
--name <NAME> Response Root type name. It is converted to PascalCase: order summary becomes OrderSummary. A name with no letters or digits becomes Response.
--lang (aliases) Output string integer float bool unknown or null optional list
ts (typescript) export interface string number number boolean unknown / null key?: T T[]
zod export const <Name>Schema = z.object(...) z.string() z.number().int() z.number() z.boolean() z.unknown() / z.null() T.nullable().optional() z.array(T)
rust (rs) Serde pub struct with #[derive(Debug, Clone, Serialize, Deserialize)] String i64 f64 bool serde_json::Value Option<T> Vec<T>
go (golang) type <Name> struct with json:"..." tags string int64 float64 bool any *T []T
pydantic (py, python) class <Name>(BaseModel) str int float bool Any / None T | None = None list[T]
mo struct <Name> ... end Text Int Float Bool Json.Value Option(T) List(T)

Field names:

  • TypeScript and Zod keep the JSON key, quoted when it is not a valid identifier ("user-id").
  • Rust converts keys to snake_case and adds #[serde(rename = "...")] when the name changed.
  • Go converts keys to PascalCase and keeps the original in the json tag.
  • Mo converts keys to snake_case.
  • Pydantic writes keys as they are.
  • An object becomes a type. Nested objects become types named after the path: parent name plus the PascalCase key (OrderSummaryMeta).
  • Fields of an object appear in alphabetical key order. In a merged array item type, they appear in the order they are first seen across the items.
  • JSON integers become integer types and other numbers become float types.
  • An array of objects becomes a list of one merged item type named <Parent><Key>Item. Keys missing from some items become optional. A key whose type differs between items is unified: integer and float give float, a type and null give an optional type, anything else gives the unknown type.
  • Any other array takes the type of its first element. An empty array is a list of the unknown type.
  • A null value outside an array of objects gets the null type.
  • If the root is not an object (an array or a scalar), Recon wraps it in a root type with one field, value.
  • The root type is printed first, then nested types.

Example input and Rust output:

{"user-id":7,"createdAt":"x","score":1,"tags":[],"items":[{"id":1,"price":2.5,"note":null},{"id":2,"price":3,"extra":true}],"meta":{"page":1}}
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrderSummary {
#[serde(rename = "createdAt")]
pub created_at: String,
pub items: Vec<OrderSummaryItemsItem>,
pub meta: OrderSummaryMeta,
pub score: i64,
pub tags: Vec<serde_json::Value>,
#[serde(rename = "user-id")]
pub user_id: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrderSummaryMeta {
pub page: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OrderSummaryItemsItem {
pub id: i64,
pub note: Option<serde_json::Value>,
pub price: f64,
pub extra: Option<bool>,
}
  • Types are printed parent first. Zod schemas and Pydantic classes refer to child types that are defined further down, so you may need to move the child definitions above the parent before the code runs.
  • Pydantic output uses JSON keys as attribute names without changes. A key such as user-id produces user-id: int, which is not valid Python.
  • A field that is null in one array item and missing in another becomes an optional null type, for example note?: null in TypeScript and note: None | None = None in Pydantic.
  • Arrays of mixed scalars take the first element’s type: [1, "a"] gives number[].
Message Cause
run `nope` not found No run with that ID in the Flight Recorder.
response body is not valid JSON The recorded body is not JSON.
parse error in `typegen`: unsupported typegen target `java`; expected ts|zod|rust|go|pydantic|mo Unknown --lang.

All are E_CLI_RUNTIME with exit status 2.

When you send a request from the web UI, or open a recorded run there, Recon scans the response body for JSON Web Tokens and decodes them. The response viewer then shows a “JWT detected” button; it opens a panel with each token’s sub, whether it has expired (or the seconds left), and the decoded payload. The CLI does not decode JWTs.

How detection works:

  • Recon looks in the response body only, not in headers, for text of the form eyJ<chars>.<chars>.<chars> using base64url characters.
  • The header and payload are base64url-decoded (no padding) and must both be JSON objects. Anything else is skipped.
  • The signature is not checked.
  • sub and iss are read when they are strings. iat and exp are read when they are integers and shown as RFC 3339 times.
  • A token is expired when exp is at or before the current time. expires_in_secs is negative after expiry.
  • The same token found twice is listed once.

The decoded tokens are returned in the jwts array of POST /api/v1/send and GET /api/v1/runs/{id}:

[
{
"expired": false,
"expires_at": "2030-01-01T00:00:00+00:00",
"expires_in_secs": 97402157,
"header": {
"alg": "HS256",
"typ": "JWT"
},
"issued_at": null,
"issuer": null,
"payload": {
"exp": 1893456000,
"scope": "sis:read",
"sub": "staff_01"
},
"subject": "staff_01",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdGFmZl8wMSIsInNjb3BlIjoic2lzOnJlYWQiLCJleHAiOjE4OTM0NTYwMDB9.demo_sig"
}
]
  • HTTP API: POST /api/v1/codegen with {"request": <RequestSpec>, "env": "local", "lang": "curl"} returns {"code": "..."}. POST /api/v1/typegen with {"json_text": "...", "root_name": "Response", "lang": "ts"} returns {"code": "..."}; root_name defaults to Response. Both need the X-Recon-Token header. See HTTP API.
  • Web UI: the “Types & Code” tab in the response viewer generates types from the shown response (root name Response) and snippets for the current request. See Web Studio.
  • There are no MCP tools for code or type generation. recon export openapi is covered in OpenAPI & ODCS Contracts.