Package: curlipie
Python library to convertcURLcommand toHTTPie.It will convertcurl-dname=admin-dshoesize=12-dcolor=green&food=wethttp://quan.hoabinh.vntohttp-fhttp://quan.hoabinh.vnname=adminshoesize=12color=greenfood=wetMotivationThis library was born when I joined a project with a team of non-Linux, non-Python developers. Because the project didn’t have proper documentation, the other team often shared API usage example to me in form of cURL command, generated from their daily-used Postman. Those cURL commands are usually ugly, like this:curl--location--requestPOST'http://app-staging.dev/api'\--header'Content-Type: application/json'\--data-raw'{
    "userId": "abc-xyz",
    "planAmount": 50000,
    "isPromotion": false,
    "createdAt": "2019-12-13 10:00:00"
}'I am more comfortable with HTTPie (shorter syntax, has highlighting and is a Python application), so I often converted it to HTTPie:http-Fapp-staging.dev/apiuserId=abc-xyzplanAmount:=50000isPromotion:=falsecreatedAt='2019-12-13 10:00:00'Though Postman can generate HTTPie, it does result in even uglier command:printf'{
    "userId": "abc-xyz",
    "planAmount": 50000,
    "isPromotion": false,
    "createdAt": "2019-12-13 10:00:00"
}'|http--follow--timeout3600POSTapp-staging.dev/api\Content-Type:'application/json'Initially, I had to do conversion manually and quickly got tired from it. I tried to find a conversion tool but failed. There is an online toolcurl2httpie.online, but it failed with above example. So I decide to write my own tool.I don’t bother to help fix the online tool above, because it is written in Go. The rich ecosystem of Python, with these built-in libraries, enable me to finish the job fast:shlex: Help parse the command line in form of shell language, handle the string escaping, quoting for me.argparse: Help parse cURL options and arguments. Note that, cURL arguments syntax follow GNU style, which is common in Linux (and Python) world but not popular in Go world (seethis tutorial), so it feels more natural with Python.Usage>>>fromcurlipieimportcurl_to_httpie>>>curl="""curl -XPUT elastic.dev/movies/_doc/1 -d '{"director": "Burton, Tim", "year": 1996, "title": "Mars Attacks!"}' -H 'Content-Type: application/json'""">>>curl_to_httpie(curl)ConversionResult(httpie="http PUT elastic.dev/movies/_doc/1 director='Burton, Tim' year:=1996 title='Mars Attacks!'",errors=[])>>>result=curl_to_httpie(curl)>>>result.httpie"http PUT elastic.dev/movies/_doc/1 director='Burton, Tim' year:=1996 title='Mars Attacks!'"Online toolCurliPie is not very usable if it stays in library form, so I made an online tool for you to use it quickly:https://curlipie.vercel.appThe site also provide HTTP API for you to develop a client for it.DevelopmentThis repo contains three components:Python librarycurlipie. This is the onepublishedto PyPI.An API server built withFastAPI, playing role of backend forcurlipie.vercel.app.A minimal frontend app built withAlpineJSandTailwindCSS.Python dependencies are managed withPoetry.To try running on localhost:Run backend with:uvicornapi.main:appThe front-end are just static files, served by backend also, so you can access it viahttp://localhost:8000/. But because TailwindCSS is configured to strip unused CSS classes, you may need to rerun this command, insidefrontend-devfolder, to keep your classes:yarnbuild-tailwindUnit test:pytestCreditBrought to you byNguyễn Hồng Quân.