FormatterHQ

cURL to Rust (reqwest) Converter

Turn any curl command into Rust code built on the reqwest blocking client, complete with the Cargo features and serde_json body you need.

Input SHELL
Output RUST
Ready.

How to use the cURL to Rust Converter

  1. Paste a curl command into the input panel.
  2. The Rust code appears automatically; click Convert after editing the command.
  3. Copy the Cargo.toml line from the top comment into your project dependencies.
  4. Paste the code into src/main.rs and run cargo run.

Convert curl to Rust with reqwest

This curl to Rust converter translates a curl command into code for reqwest, the most widely used HTTP client crate in Rust. It targets the reqwest::blocking API so the result is a plain fn main() with no async runtime to set up, and it returns Result<(), Box<dyn std::error::Error>> so every call can use ?.

Example output

For a JSON POST with a bearer token and --max-time 30, the converter produces:

let client = reqwest::blocking::Client::builder().timeout(std::time::Duration::from_secs(30)).redirect(reqwest::redirect::Policy::none()).build()?;let res = client.post("https://api.example.com/v1/orders?notify=true").header("Authorization", "Bearer YOUR_API_TOKEN").json(&serde_json::json!({"customer_id": 42,"gift": false})).send()?;

The first line of the output is a comment with the exact dependency to add, for example reqwest = { version = "0.12", features = ["blocking", "json"] } plus serde_json = "1". The multipart feature is added only when the command uses -F.

How curl options are mapped

  • JSON bodies: when the Content-Type is JSON and the body parses, it becomes a serde_json::json! macro passed to .json(). reqwest then sets the Content-Type header itself, so the duplicate header is dropped.
  • Other bodies: non-JSON data is sent with .body(). A bare -d also gets an explicit application/x-www-form-urlencoded header.
  • Methods: GET, POST, PUT, PATCH, DELETE and HEAD use the matching shortcut such as client.post(). Anything else uses reqwest::Method::from_bytes.
  • Auth: -u user:pass becomes .basic_auth(user, Some(pass)).
  • Uploads: -F fields build a multipart::Form with .text() and .file().
  • Client settings: --max-time sets .timeout() and -k adds .danger_accept_invalid_certs(true).

Redirects and other differences

curl does not follow redirects unless you pass -L, but reqwest does by default. To keep the behavior identical, the converter adds .redirect(reqwest::redirect::Policy::none()) when -L is missing. Remove that line if you want reqwest's default of up to 10 hops.

The generated program prints res.status() and the body text. If you want non-2xx responses to become errors, chain .error_for_status()? after .send()?.

Proxy settings, client certificates and retries are not converted. Options with no mapping are listed as comments at the top of the output. Data read from a file with -d @file becomes a placeholder you need to replace.

Running the output in a new project

cargo new curl_test && cd curl_test
cargo add reqwest --features blocking,json
cargo add serde_json
# paste the converted code into src/main.rs
cargo run

The blocking client is meant for scripts and command-line tools. Do not call it from inside an async runtime such as a Tokio #[tokio::main] function: reqwest's blocking client starts its own runtime internally and panics when it is used inside another one. In async code, drop the blocking feature and add .await after .send() and .text() instead, as described in the FAQ below.

Privacy

Everything runs locally in your browser, so tokens and passwords in the command stay on your machine. For other languages, see curl to Go and curl to Python, or generate response structs with JSON to Rust.

Frequently asked questions

Can I get async reqwest code instead of blocking?
The tool generates the blocking API because it runs without a runtime. To go async, drop the blocking feature, add tokio, mark main with #[tokio::main], and put .await after .send() and .text().
Why is my Content-Type header missing from the Rust code?
For JSON bodies the converter uses .json(), which sets Content-Type: application/json automatically. Keeping your header as well would send it twice, so it is removed.
Which reqwest version does the output target?
The dependency comment uses reqwest 0.12 with the needed features. The builder methods used here have been stable for many releases, so older 0.11 projects usually compile with little or no change.
How do I deserialize the response into a struct?
Enable the json feature, derive serde::Deserialize on your struct, and call res.json::<MyType>()? instead of res.text()?. The JSON to Rust tool can generate the struct from a sample response.

Last updated September 26, 2026

Related tools

cURL to Axios (Node.js) Converter Convert curl commands to Node.js axios requests with params, headers, JSON data, auth, form-data uploads and timeouts. cURL to C# Converter Convert curl commands to C# HttpClient code for .NET with headers, content types, basic auth, multipart and TLS options. cURL to Go Converter Convert curl commands into Go code using net/http — method, headers, JSON or form body, basic auth, timeouts and multipart uploads. cURL to PHP Guzzle Converter Convert curl commands to PHP Guzzle requests using json, form_params, multipart, query and auth options. cURL to Java Converter Convert curl commands to Java 11+ java.net.http.HttpClient code with headers, body, redirects and timeouts. cURL to JavaScript Fetch Convert curl commands into JavaScript fetch() code with method, headers, JSON body, form data, basic auth and timeouts. Date & Time Calculator Calculate the difference between two dates or add/subtract days, weeks, months and years from a date. Docker Run to Docker Compose Convert one or more docker run commands into a docker-compose.yml: ports, volumes, env, restart, networks, healthchecks and more. File Type Checker Find out what a file really is from its content, not its name. Detects 150+ formats and warns when the extension does not match. HTTP Status Codes Searchable list of the HTTP status codes in use, from 100 to 511, with a plain explanation of when each response is used. JWT Decoder Decode a JSON Web Token to inspect its header, payload claims and expiry time, and verify its signature with your key. Runs locally. JWT Encoder & Generator Create and sign JSON Web Tokens with HS256, RS256, ES256, PS256 or EdDSA using a secret or PEM key. Signing happens in your browser.