Coder Social home page Coder Social logo

morn-0 / curl-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tyrchen/curl-parser

0.0 0.0 0.0 43 KB

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

License: MIT License

Rust 97.11% Makefile 2.89%

curl-parser's Introduction

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.

curl-parser's People

Contributors

tyrchen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.