curl-parser

Crates.iocurl-parser
lib.rscurl-parser
version0.3.1
sourcesrc
created_at2023-02-09 06:07:07.742215
updated_at2023-12-18 00:39:45.2062
descriptionConvert curl command to a ParsedRequest (could be further converted to reqwest::RequestBuilder)
homepagehttps://github.com/tyrchen/curl-parser
repositoryhttps://github.com/tyrchen/curl-parser
max_upload_size
id780539
size69,379
Tyr Chen (tyrchen)

documentation

https://docs.rs/curl-parser

README

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.

Commit count: 18

cargo fmt