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.

Built and maintained by Udit Agarwal

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

  • Generates an async fn main() wired up with #[tokio::main] and reqwest::Client
  • Maps the curl method to the matching reqwest::Method, including custom verbs
  • Builds a HeaderMap from every -H/--header flag
  • Uses .json(&serde_json::json!(...)) for valid JSON bodies and .body(...) for form or raw payloads
  • Converts -u/--user into an idiomatic .basic_auth(username, Some(password)) call
  • Pretty-prints JSON bodies so the literal is easy to read and edit
  • Warns about flags with no reqwest equivalent, like -k and output-to-file options
  • Copy the result or download it as request.rs with one click

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

  • The output uses .body(...) when you expected .json(...). — Send the body with --json or add -H "Content-Type: application/json" so the converter recognizes it as JSON and switches to .json(...).
  • Compiling the code fails with an unresolved crate serde_json or tokio. — Add reqwest (with the json feature), serde_json, and tokio (with the full feature) as dependencies in Cargo.toml; the generated code targets those crates.
  • A JSON body comes out as a quoted string instead of an object literal. — That happens when the body is not valid JSON. Fix the JSON, or keep it as a string and send it with .body(...).
  • The .basic_auth(...) call is missing even though the curl command used -u. — Make sure the -u value is exactly user:pass. The converter decodes the Basic auth header it generates internally to recover the username and password.

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

  • cURL to Fetch — Convert a curl command to a JavaScript fetch() call.
  • cURL to Python — Convert a curl command to Python requests code.
  • cURL to Go — Convert a curl command to Go net/http code.
  • cURL to Node.js (axios) — Convert a curl command to Node.js axios code.
  • cURL to PHP — Convert a curl command to PHP cURL code.
  • API Request Client — Send HTTP requests, build headers and params, inspect responses — your last 25 requests are saved locally.

Guides

More API Tools tools

  • HAR to cURL — Turn requests from a browser HAR file into runnable cURL commands, with secrets stripped.
  • Postman to cURL — Turn a Postman collection export into runnable cURL commands, variables resolved.
  • cURL to C# — Convert a curl command to C# HttpClient code.
  • cURL to Java — Convert a curl command to Java 11 HttpClient code.
  • cURL to Ruby — Convert a curl command to Ruby Net::HTTP code.
  • cURL to PowerShell — Convert a curl command to PowerShell Invoke-RestMethod.
  • cURL to Swift — Turn a curl command into Swift code that uses URLSession.
  • cURL to Dart — Turn a curl command into Dart code for Flutter using package:http.
  • cURL to Fetch — Convert a curl command to a JavaScript fetch() call.
  • URL Parser — Break a URL into its parts and list query parameters.
  • API Request Client — Send HTTP requests, build headers and params, inspect responses — your last 25 requests are saved locally.
  • URL Builder & UTM Generator — Construct and validate fully encoded production URLs with standard analytics query flags (UTM) or custom query arrays.

See all API Tools tools (24) · All tools