Skip to content
koducathome

cURL to Rust Converter

Convert curl commands to Rust code using reqwest. Paste a command and the Rust snippet appears instantly — everything runs in your browser.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The Rust reqwest code appears instantly.
  3. Set up: Add to Cargo.toml: reqwest = { version = "0.12", features = ["blocking", "json"] } and serde_json = "1".
  4. Run it: Put the code in src/main.rs and run cargo run. Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no reqwest equivalent.

Example

GET with headers → Rust reqwest

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
Rust reqwest
// Cargo.toml dependencies:
// reqwest = { version = "0.12", features = ["blocking"] }

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::blocking::Client::new();

    let response = client
        .get("https://api.example.com/v1/users?page=2")
        .header("Accept", "application/json")
        .header("Authorization", "Bearer YOUR_TOKEN")
        .send()?;

    println!("{}", response.status());
    println!("{}", response.text()?);
    Ok(())
}

Common use cases

  • Rust CLIs and tools
  • Services calling external APIs

Converting curl to Rust reqwest

reqwest is Rust's most popular HTTP client. The code uses its blocking client, with serde_json for JSON bodies.

The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent reqwest code. Options that have no reqwest equivalent are listed under the editors rather than silently dropped.

Limitations

  • The code is a starting point: add timeouts, retries and error handling for production use.
  • Secrets in the curl command are copied into the code — move them to environment variables before committing.

Frequently asked questions

Why the blocking client?

It keeps the example simple with no async runtime. In async code, use reqwest::Client with Tokio and .await.

Which Cargo features are needed?

blocking for the blocking client and json for .json(...), as listed at the top of the code.

Is my curl command sent to a server?

No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.