Convert curl to Rust
curl2code converts curl commands to Rust code using the reqwest crate. The conversion runs in your browser via WebAssembly for complete privacy. For Go, check our curl to Go converter. For C, see curl to C. Below are practical Rust examples with async/await.
How to copy curl from your browser
- 1
Open DevTools
Press F12 or Ctrl+Shift+I to open your browser developer tools.
- 2
Go to the Network tab
Click the Network tab and perform the action that triggers the HTTP request.
- 3
Copy as cURL
Right-click the request → Copy → Copy as cURL. Then paste it above.
Frequently Asked Questions
What is Rust reqwest?
reqwest is the most popular HTTP client for Rust, built on top of hyper. It provides both blocking and async APIs, automatic JSON serialization via serde, TLS, cookie handling, and proxy support. Add with cargo add reqwest --features json. It's the default library curl2code uses for Rust conversions.
reqwest vs hyper vs ureq — which should I use?
reqwest is the go-to for most projects — high-level, feature-rich, and async. hyper is lower-level and gives maximum control (reqwest is built on it). ureq is a minimal, blocking-only client with no async runtime dependency. For a similar standard-library approach, see curl to Go or curl to C.
How to handle authentication in Rust?
For Bearer: client.get(url).bearer_auth(token). For Basic: client.get(url).basic_auth(user, Some(pass)). Or set headers manually with .header("Authorization", value). curl2code converts -u and -H 'Authorization: ...' flags to the appropriate reqwest methods.
How to send multipart form data in Rust?
Use reqwest::multipart::Form: create with Form::new(), add text fields with .text("key", "value"), and files with .file("field", path).await?. Pass to client.post(url).multipart(form). curl2code handles -F flags for reqwest multipart.
How to handle HTTP errors in Rust?
reqwest returns Result wrapping Response on success or reqwest::Error on failure — use the ? operator for propagation. Check response.status().is_success() or call response.error_for_status()? which converts non-2xx codes to errors. Rust's type system ensures all error paths are explicitly handled at compile time.
Which async runtime does reqwest need?
reqwest requires the tokio runtime by default. Annotate your main with #[tokio::main]. For blocking usage without an async runtime, enable the blocking feature and use reqwest::blocking::Client. curl2code generates async code with tokio by default. For another async ecosystem, see curl to Go (goroutines).
How to set timeouts in Rust reqwest?
Set on the client: Client::builder().timeout(Duration::from_secs(30)).connect_timeout(Duration::from_secs(10)).build()?. Per-request: client.get(url).timeout(Duration::from_secs(5)). These map to curl's --max-time and --connect-timeout flags.
How to use a proxy with reqwest?
Set a proxy on the client builder: Client::builder().proxy(Proxy::https("http://proxy:8080")?).build()?. Supports HTTP, HTTPS, and SOCKS5 proxies. reqwest also respects HTTP_PROXY and HTTPS_PROXY environment variables by default. curl2code converts -x flags to proxy configuration.
How to send a POST request with JSON body in Rust?
Convert a curl POST command like curl -X POST -H "Content-Type: application/json" -d "{"key":"value"}" URL to Rust using curl2code. The generated code uses client.post(url).json(&data).send().await?. curl2code automatically detects -d/--data flags with JSON content and sets the appropriate Content-Type header in the reqwest code.
How to add Bearer token authorization in Rust?
Pass curl -H "Authorization: Bearer YOUR_TOKEN" URL to curl2code and it generates reqwest code with the auth header: .bearer_auth("YOUR_TOKEN"). curl2code detects Bearer tokens from both -H "Authorization: Bearer ..." and --oauth2-bearer flags. For Basic auth, use -u user:pass.
How to set Content-Type header in Rust?
curl2code converts curl -H "Content-Type: application/json" URL to reqwest code with the proper header: .header("Content-Type", "application/json"). For -d data, curl defaults to application/x-www-form-urlencoded; for -F form uploads, it uses multipart/form-data. curl2code maps each to the correct reqwest API.