curl to Rust Converter

Convert a curl command to Rust reqwest code instantly in your browser. The command stays on your device.

Your curl command is converted to Rust locally in your browser and never uploaded, but avoid pasting real production tokens or credentials into any tool.

Also convert curl to JavaScript fetch

About cURL to Rust

cURL to Rust takes a curl command you copied from a terminal, browser DevTools, or API docs and rewrites it as an async Rust program built on the reqwest crate. It reads flags like -X, -H, -d, --data-raw, --json, -u, and -G, picks the right reqwest::Method, and chooses .json(...) for valid JSON bodies or .body(...) for form and raw payloads so the request matches what curl would actually send. A -u/--user flag becomes an idiomatic .basic_auth(...) call instead of a raw header. It is handy when you are porting a quick API test into a Rust service, a CLI tool, or an integration test without hand-writing reqwest boilerplate. The whole conversion runs in your browser, so the curl command and any tokens inside it are processed locally on your device and are never uploaded.

Features

How to use the cURL to Rust

  1. Paste your curl command into the cURL command box.
  2. Read the generated Rust reqwest program in the output panel.
  3. Check the warning banner for any flags that were adjusted or skipped.
  4. Click Copy, or download the code as request.rs.

Example

Input

curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"Ada"}'

Output

use reqwest::header::{HeaderMap, HeaderName, HeaderValue};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();

    let mut headers = HeaderMap::new();
    headers.insert(HeaderName::from_bytes(b"Content-Type")?, HeaderValue::from_str("application/json")?);

    let response = client
        .request(reqwest::Method::POST, "https://api.example.com/users")
        .headers(headers)
        .json(&serde_json::json!({
            "name": "Ada"
        }))
        .send()
        .await?;

    println!("{}", response.status());
    let body = response.text().await?;
    println!("{}", body);

    Ok(())
}

A JSON body is passed with .json(...) so reqwest serializes it for you.

Common errors & troubleshooting

Frequently asked questions

How do I convert a curl command to Rust?
Paste the curl command into the input box and cURL to Rust renders an async reqwest program on the right that you can copy or download as request.rs.
Does cURL to Rust generate code for reqwest or another HTTP client?
It targets the popular reqwest crate with tokio as the async runtime and emits an async fn main() using #[tokio::main]. Add both crates to your Cargo.toml before running the code.
When does the converter use .json(...) versus .body(...)?
It uses .json(&serde_json::json!(...)) when the body is valid JSON (sent with --json or a JSON Content-Type), and .body(...) for form-encoded or raw string bodies.
How is a curl -u basic auth value handled in the Rust output?
A -u or --user value is rendered as .basic_auth(username, Some(password)) on the request builder, rather than a manually constructed Authorization header.
Is my curl command uploaded when I convert it to Rust?
No. The curl to Rust conversion runs entirely in your browser, so the command and any credentials in it stay on your device.
What crates does the generated reqwest code depend on?
The output expects reqwest (json feature enabled), serde_json, and tokio (full feature) as dependencies — add them with cargo add before compiling.

Related tools

All ArrayKit tools