#curl #reqwest #command #convert #request-builder #further #parser

curl-parser

Convert curl command to a ParsedRequest (could be further converted to reqwest::RequestBuilder)

9 unstable releases (4 breaking)

0.5.0 Jan 7, 2025
0.4.4 Jan 6, 2025
0.3.1 Dec 18, 2023
0.2.1 Feb 9, 2023
0.1.1 Feb 9, 2023

#475 in Web programming

Download history 55/week @ 2024-09-25 24/week @ 2024-10-02 39/week @ 2024-10-09 37/week @ 2024-10-16 77/week @ 2024-10-23 53/week @ 2024-10-30 23/week @ 2024-11-06 18/week @ 2024-11-13 53/week @ 2024-11-20 29/week @ 2024-11-27 26/week @ 2024-12-04 32/week @ 2024-12-11 23/week @ 2024-12-18 61/week @ 2024-12-25 679/week @ 2025-01-01 248/week @ 2025-01-08

1,016 downloads per month
Used in atac

MIT license

27KB
373 lines

CURL Parser

Nowadays, most of the APIs provide CURL examples to allow users to try out the APIs without any entry barriers, but it takes time to digest the examples and convert them into Rust code. This crate could convert CURL commands into Rust code.

At the moment, it supports -X, -H, -d and -u options since these are the most widely used ones.

Usage

let input = r#"curl \
    -X PATCH \
    -d '{"visibility":"private"}' \
    -H "Accept: application/vnd.github+json" \
    -H "Authorization: Bearer {{ token }}"\
    -H "X-GitHub-Api-Version: 2022-11-28" \
    https://api.github.com/user/email/visibility "#;
let context = json!({ "token": "abcd1234" });
let parsed = curl_parser::ParsedRequest::load(input, Some(context)) ?;
println!("{:#?}", parsed);
let req: reqwest::RequestBuilder = parsed.try_into()?;
let res = req.send().await?;
assert_eq!(res.status(), 200);

By default, reqwest is enabled so that you can convert ParsedRequest into a reqwest::RequestBuilder. If you don't want to use reqwest, you can disable the default features.

Dependencies

~7–18MB
~254K SLoC