cURL converter · Rust
cURL to Rust
Paste a curl command and get a compiling Rust snippet. Headers use HeaderName::from_str + HeaderValue::from_str so runtime strings work, not just static byte literals.
InputcURL command
1 secret
MethodPOST·Headers2·Body46 B· Chars 187
OutputRust · reqwest(blocking)
// Cargo.toml: reqwest = { version = "0.12", features = ["json", "blocking", "gzip", "brotli"] }
use reqwest::blocking::Client;
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use std::str::FromStr;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::builder().redirect(reqwest::redirect::Policy::none()).build()?;
let mut headers = HeaderMap::new();
headers.insert(HeaderName::from_str("authorization")?, HeaderValue::from_str("Bearer sk_test_123")?);
headers.insert(HeaderName::from_str("content-type")?, HeaderValue::from_str("application/json")?);
let mut req = client.post("https://api.example.com/v1/messages").headers(headers);
req = req.body("{\"to\":\"+15551234567\",\"body\":\"Hello from curl\"}");
let resp = req.send()?;
println!("{}", resp.text()?);
Ok(())
}Inspect
Top guides for Rust
All guides →Common questions
- Blocking or async?
- The snippet uses reqwest's blocking client for readability. Drop 'blocking' and add .await to switch to Tokio.
- Why from_str for headers?
- HeaderValue::from_static rejects runtime strings. from_str is fallible but works with anything you paste.
- Basic auth?
- -u user:pass compiles to req.basic_auth('user', Some('pass')) — reqwest builds the Authorization header for you.
- Is my curl sent anywhere?
- No. Parsing is client-side.
Also convert cURL to
All guides →Same parser, same idiomatic output — swap the target language whenever your stack changes. Every hub carries its own reference guides for methods, payloads, and auth.