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

curl-parser

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

4 releases (2 breaking)

0.3.1 Dec 18, 2023
0.2.1 Feb 9, 2023
0.2.0 Feb 9, 2023
0.1.1 Feb 9, 2023

#808 in Web programming

Download history 6/week @ 2024-03-27 8/week @ 2024-04-03 2/week @ 2024-05-15 4/week @ 2024-05-29 7/week @ 2024-06-05 6/week @ 2024-06-12 7/week @ 2024-06-19 30/week @ 2024-06-26

52 downloads per month
Used in atac

MIT license

22KB
329 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 <YOUR-TOKEN>"\
    -H "X-GitHub-Api-Version: 2022-11-28" \
    https://api.github.com/user/email/visibility "#;
let parsed = curl_parser::ParsedRequest::try_from(input)?;
println!("{:#?}", parsed);
let req: reqwest::RequestBuilder = parsed.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

~6–19MB
~291K SLoC