TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Convert curl commands to code in several languages

262 点作者 djha-skin大约 3 年前

35 条评论

NickC_dev大约 3 年前
Original author here. Many smart people have contributed code over the years, but one warrants special mention.<p>About a year ago, verhovsky showed up out of nowhere. He rewrote the core of the application and increased the professionalism across the board. (dedicated domain, github page hosting, UI refresh, privacy improvements, and much more)<p>The tree-sitter PR is a monster achievement: <a href="https:&#x2F;&#x2F;github.com&#x2F;curlconverter&#x2F;curlconverter&#x2F;pull&#x2F;278" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;curlconverter&#x2F;curlconverter&#x2F;pull&#x2F;278</a><p>Search for parseAnsiCString in there. I don&#x27;t think that had ever been implemented in JavaScript before.<p>For you, verhovsky, 10x engineer might be an understatement. Thank you!
评论 #30645482 未加载
detaro大约 3 年前
Seems to be mostly doing text-replacement and not actually understand what it&#x27;s handling and what it can&#x27;t actually do: <a href="https:&#x2F;&#x2F;github.com&#x2F;icing&#x2F;blog&#x2F;blob&#x2F;main&#x2F;curl_on_a_weekend.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;icing&#x2F;blog&#x2F;blob&#x2F;main&#x2F;curl_on_a_weekend.md</a> (not my article, saw the link on twitter today)<p>E.g. it turns curl ftp:&#x2F;&#x2F;host.com into response = requests.get(&#x27;<a href="http:&#x2F;&#x2F;ftp:&#x2F;&#x2F;host.com" rel="nofollow">http:&#x2F;&#x2F;ftp:&#x2F;&#x2F;host.com</a>&#x27;)
protoman3000大约 3 年前
Anybody else having reached the point of language indifference&#x2F;boredom?<p>Everything I everywhere now see is just the same: Gluecode, library calls, unnecessary verbosity, Blackbox inside Blackbox etc.<p>And this project slaps it again into my face, with every example it’s literally always the same - only that language uses a colon, the other a semicolon, the other catches exceptions with ? etc. but in a way it’s all just the same.<p>How to overcome this?<p>I find, only pointfree notation has some beauty to it that makes reading code sweet again.
评论 #30644304 未加载
评论 #30645732 未加载
评论 #30646405 未加载
评论 #30643963 未加载
评论 #30644934 未加载
评论 #30643957 未加载
评论 #30644941 未加载
评论 #30643966 未加载
评论 #30645578 未加载
评论 #30646543 未加载
评论 #30649024 未加载
评论 #30647453 未加载
jraph大约 3 年前
With the feature of browsers to copy requests as Curl and now this, it&#x27;s funny to see curl commands be(com)ing some kind of lingua franca for HTTP request representation!<p>Now you can play a request and boom, you have your code to make this request in your favorite programming language.
codazoda大约 3 年前
It&#x27;s interesting and I like it. It does seem to be rather opinionated without saying so. The PHP example requires an http library I hadn&#x27;t heard of (rmccue&#x2F;requests). Copy&#x2F;paste of that code doesn&#x27;t work unless you know how to find and install that library. The related tool they reference, however, does work using the PHP curl library.<p>I presume they were trying to keep the code to 4 lines or so. The curl library in PHP is rather verbose and requires 5 to 8 lines (depending on if you try to catch the error).<p><a href="https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;book.curl.php" rel="nofollow">https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;book.curl.php</a>
评论 #30644751 未加载
rgovostes大约 3 年前
I wrote http-translator which is one of the linked related projects. It has a smaller feature set, but is just a few hundred lines and can be easily extended to support new frontends (input formats other than curl) and backends (i.e., output languages).<p><a href="https:&#x2F;&#x2F;ryan.govost.es&#x2F;http-translator&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ryan.govost.es&#x2F;http-translator&#x2F;</a> | <a href="https:&#x2F;&#x2F;github.com&#x2F;rgov&#x2F;http-translator" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rgov&#x2F;http-translator</a><p>Mine was a project for learning modern-ish JavaScript, and I found that packages for parsing command line arguments in JS were generally poor. I wrote my own shell lexer that is simpler than Eric S. Raymond&#x27;s in the Python standard library while passing the test suite, and since Burp Suite generates curl commands that use Bash ANSI C strings, I support those too. <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;shlex" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;shlex</a><p>If I were to do further development, I would ditch my curl command line parsing in favor of building curl with Emscripten and having it generate the full HTTP request, then leverage the existing request parser.<p>curl already supports a —-libcurl flag that generates equivalent C code, and it might be easy to extract the curl_easy_setopt() calls from it.<p>Both our projects should probably support the built-in urllib.request for Python; Requests isn’t always necessary anymore.
johnx123-up大约 3 年前
Few other similar open source projects:<p>1. <a href="https:&#x2F;&#x2F;github.com&#x2F;mholt&#x2F;curl-to-go" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mholt&#x2F;curl-to-go</a><p>2. <a href="https:&#x2F;&#x2F;github.com&#x2F;incarnate&#x2F;curl-to-php" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;incarnate&#x2F;curl-to-php</a>
评论 #30643765 未加载
评论 #30643499 未加载
评论 #30643571 未加载
oefrha大约 3 年前
I use Paw[1] for this, which is obviously a lot more powerful by allowing me to easily toggle and&#x2F;or modify query params, headers, edit body as structured JSON &#x2F; XML &#x2F; application&#x2F;x-www-form-urlencoded &#x2F; multipart&#x2F;form-data, etc. Probably doable in other API clients like Insomnia[2], too.<p>[1] <a href="https:&#x2F;&#x2F;paw.cloud&#x2F;" rel="nofollow">https:&#x2F;&#x2F;paw.cloud&#x2F;</a><p>[2] <a href="https:&#x2F;&#x2F;insomnia.rest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;insomnia.rest&#x2F;</a>
评论 #30642892 未加载
folli大约 3 年前
As a Java hobbyist, I&#x27;m dying seeing the difference between the Java boilerplate and the Python two-liner
评论 #30643027 未加载
lambic大约 3 年前
I feel like more granular options would be useful here like &quot;Python with beautifulsoup&quot; or &quot;PHP with Guzzle&quot;.
评论 #30644287 未加载
gscho大约 3 年前
Here&#x27;s the one I often use for Ruby. <a href="https:&#x2F;&#x2F;jhawthorn.github.io&#x2F;curl-to-ruby&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jhawthorn.github.io&#x2F;curl-to-ruby&#x2F;</a>
评论 #30649055 未加载
steerablesafe大约 3 年前
I expected C with libcurl on the list, but in a sense that might be the toughest to implement.
评论 #30643100 未加载
评论 #30643077 未加载
sethammons大约 3 年前
I haven&#x27;t touched it in years, but I made a utility to do the opposite in Go. Start with Go&#x27;s request and transform it into a curl call. It was helpful for testing at the time. Looking at it, wow, that was 7 years ago!<p><a href="https:&#x2F;&#x2F;github.com&#x2F;sethgrid&#x2F;gencurl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sethgrid&#x2F;gencurl</a>
benbristow大约 3 年前
Something a bit different but I&#x27;m a huge fan of NSwag recently.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;RicoSuter&#x2F;NSwag" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;RicoSuter&#x2F;NSwag</a><p>We use it on a project at work in C# and I&#x27;ve also been using it personally on pet projects with TypeScript.<p>Allows you to automatically generate REST API clients based on Swagger&#x2F;OpenAPI specs and is very customizable.<p>Really nice if building out microservices and you&#x27;re wanting to communicate between each other or building web apps and want to communicate with APIs. Saves a lot of time writing code to make requests and handle different status codes etc. Automatically generates all the classes&#x2F;interfaces with sane naming schemes etc.<p>Even has a GUI application to generate the configs also if you wish.
capableweb大约 3 年前
I agree with the comments saying it should say &quot;Language + Client library&quot; instead of just language, as there are many ways of doing requests with different libraries.<p>Also, funny enough, the first command I tried didn&#x27;t work as I expected, but thinking about it, it also seems hard to implement correctly. The cURL command I tried was &quot;curl -v <a href="https:&#x2F;&#x2F;google.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;google.com&#x2F;</a>&quot; but none of the implementations include verbose logging.<p>Weirdly, JSON is listed there, and it is absolutely not clear how JSON can be considered a language that can make HTTP requests. I wonder what client library that is?
评论 #30644396 未加载
kevinsundar大约 3 年前
I always thought this would be a cool feature to have in a http library. The library knows the best way to convert a curl command to its own internal representation. Something like requests.from_curl()
beranabus大约 3 年前
The go version seems to be missing timeouts. There is none by default and the --connect-timeout flag is not setting one either.
评论 #30647754 未加载
akmittal大约 3 年前
This looks great, was working myself on same. Good that i saw the link without wasting anymore time.<p>Had completed UI part as of now <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=30642254" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=30642254</a>
verhovsky大约 3 年前
I work on this tool (but I&#x27;m not the original author), feel free to ask me questions.
svnpenn大约 3 年前
I have a similar tool for Go:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;89z&#x2F;format&#x2F;tree&#x2F;master&#x2F;cmd&#x2F;net" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;89z&#x2F;format&#x2F;tree&#x2F;master&#x2F;cmd&#x2F;net</a>
chazeon大约 3 年前
I hope there is a better way to stringify &#x2F; parse these headers and stuff; curl options seems be the best way there is right now. Unfortunately Insomnia etc. does not parse these.
spacemanmatt大约 3 年前
I&#x27;ve gotten a lot out of Chrome debugger&#x27;s &quot;copy request as cURL&quot; (among others) functionality. I gotta like seeing more of this kind of thing in the wild.
评论 #30643084 未加载
awsanswers大约 3 年前
I just noticed yesterday that Postman has functionality like this, with over 20 options for the language or language+framework used.
debdut大约 3 年前
Awesome work! I&#x27;m amazed at how many low hanging easy but really really useful projects are left to be done! It seems infinite
tkiolp4大约 3 年前
The amount of boilerplate Go code for a simple GET is astonishing. I love Go, but sometimes I miss the succinctness of Python.
评论 #30646074 未加载
account-5大约 3 年前
I&#x27;m struggling to get VBA to accept a .pem client cert as well as a username and password. Wish this has VBA.
po1nt大约 3 年前
I&#x27;m a bit dissapointed it doesn&#x27;t convert into raw curl module function calls in PHP.
评论 #30732595 未加载
评论 #30643991 未加载
google234123大约 3 年前
I want to see C++ which I would guess stars with importing asio.
dulvui大约 3 年前
Why should you do this in Java:<p>httpConn.getResponseCode() &#x2F; 100 == 2<p>instead of:<p>httpConn.getResponseCode() == 200
评论 #30643552 未加载
评论 #30643630 未加载
评论 #30646142 未加载
评论 #30643546 未加载
评论 #30643545 未加载
eu大约 3 年前
I like `curlify` to convert from `python requests` to `curl`
dontchooseanick大约 3 年前
Where is haskell :) ?
hanniabu大约 3 年前
I&#x27;m surprised it doesn&#x27;t support Javascript
评论 #30643590 未加载
评论 #30655294 未加载
croes大约 3 年前
JSON?
cushychicken大约 3 年前
Love curl converter!<p>They even have some resources to let you turn into python, go, and a few other languages.
racl101大约 3 年前
That is very cool!