cURLParse cURL Converter

Convert cURL to Rust (reqwest)

Paste a curl command to get the same request as async Rust using reqwest on Tokio. Below the converter, each flag is shown with the exact lines it adds, along with the Cargo features and client settings that some curl behavior needs.

cURL Converter Engine 100% CLIENT-SIDE
Target Language
Python (requests)
POST 200
cURL Command
Generated Code

What each curl flag becomes in Rust reqwest

Each example below is the converter's real output, generated when this page was built, from the same code the box above runs. Only the lines a flag adds are shown, compared with converting a bare curl URL, so you can see exactly where each piece of the command lands in Rust.

-H · Request headers

curl

curl https://api.example.com/items -H "Accept: application/json" -H "X-Request-Id: 42"

Lines it adds to the Rust reqwest code

    req = req.header("Accept", "application/json");
    req = req.header("X-Request-Id", "42");

--json · A JSON body

--json is curl shorthand for a body plus both Content-Type: application/json and Accept: application/json, so both headers appear.

curl

curl https://api.example.com/items --json '{"name":"widget","qty":2}'

Lines it adds to the Rust reqwest code

    let mut req = client.post(url);
    req = req.header("Content-Type", "application/json");
    req = req.header("Accept", "application/json");
    req = req.body("{\"name\":\"widget\",\"qty\":2}");

-d · A form body

Two -d flags join with &, any -d makes the request a POST, and curl labels the body application/x-www-form-urlencoded unless you set a Content-Type yourself.

curl

curl https://api.example.com/login -d "user=ada" -d "remember=1"

Lines it adds to the Rust reqwest code

    let mut req = client.post(url);
    req = req.header("Content-Type", "application/x-www-form-urlencoded");
    req = req.body("user=ada&remember=1");

-G · Data sent as query parameters

-G moves the data into the URL and sends a GET with no body and no Content-Type, which is what curl puts on the wire.

curl

curl -G https://api.example.com/search --data-urlencode "q=café au lait"

Lines it adds to the Rust reqwest code

    let url = "https://api.example.com/search?q=caf%C3%A9+au+lait";

-u · Basic authentication

-u becomes an Authorization: Basic header with the base64 of user:password. If the command also sets its own Authorization header, that header wins, as it does in curl.

curl

curl -u ada:s3cret https://api.example.com/me

Lines it adds to the Rust reqwest code

    req = req.header("Authorization", "Basic YWRhOnMzY3JldA==");

-b · Cookies

curl

curl -b "session=abc123; theme=dark" https://api.example.com/me

Lines it adds to the Rust reqwest code

    req = req.header("Cookie", "session=abc123; theme=dark");

-F · A multipart upload

curl

curl https://api.example.com/upload -F "title=Q3 report" -F "file=@report.pdf"

Lines it adds to the Rust reqwest code

    let mut req = client.post(url);
    // The multipart feature builds the body and its Content-Type together;
    // attaching a file from disk also needs the stream feature:
    // cargo add reqwest --features multipart,stream
    let mut form = reqwest::multipart::Form::new();
    form = form.text("title", "Q3 report");
    form = form.file("file", "report.pdf").await?;
    req = req.multipart(form);

The converter also notes: a -F upload needs Content-Type: multipart/form-data with a boundary generated per request, so the target language sets that header itself.

-X · A different method

curl

curl -X DELETE https://api.example.com/items/7

Lines it adds to the Rust reqwest code

    let mut req = client.delete(url);

-I · A HEAD request

curl

curl -I https://api.example.com/health

Lines it adds to the Rust reqwest code

    let mut req = client.head(url);

What the generated code does not carry over

Some curl flags change how the transfer behaves rather than what the request is, and the converter leaves them out. For each flag below, this build checked that adding it leaves the Rust reqwest output unchanged, then noted what reqwest does by default and how to match curl:

More from cURLParse

Guides

All tools →All 15 guides →

Frequently Asked Questions

Which Cargo features does the generated reqwest code need?

reqwest itself, plus tokio with the macros and rt-multi-thread features for the #[tokio::main] entry point. A -F upload also needs reqwest's multipart and stream features, which the generated code notes in a comment, and decoding gzip responses needs the gzip feature.

Does reqwest follow redirects like curl -L?

Yes. By default reqwest follows up to 10 redirects, which is what curl does with -L. Without -L, curl stops at the first 3xx; to reproduce that, build the client with .redirect(reqwest::redirect::Policy::none()).

Developer Sponsor / Partner
Copied to clipboard!