9 ms·
Online curl command line builder
- sleepyhead 11y agoOr use https://github.com/jakubroztocil/httpie https://github.com/jakubroztocil/httpie
- tuxone 11y agohttpie is awesome, but in some environment all you have is curl.
- _mikz 11y agowhat is so hard about remembering how to use curl? I was hoping for some JS library that would generate the commands with proper escaping etc.
- tuxone 11y agoI have two "problems" with curl. First I have to remember every kind of HTTP header (no autocomplete) and second write/edit command lines (especially JSON bodies etc) is a bit unfriendly. Of course this is just a 10 minutes experiment.
- vog 11y agoNice idea, but this tool doesn't escape URLs properly. The biggest problem are "&" characters, but also "?" characters make trouble in some shells (e.g. zsh).
- tuxone 11y agoThank you for you feedback, does adding double quotes solve the problem?
- deleted 11y ago[deleted]
- Tiksi 11y agoSingle quotes would be better, you can still run into trouble with things getting parsed in double quotes. Edit: Example of this in zsh: # tiksi@layla ~ $ echo "http://example.com/uid=${thisisgone}-$(date)`pwd`\n\x00\x00nulletc\x0a" [09:38:50] http://example.com/uid=-Thu Apr 23 09:38:53 EDT 2015/home/tiksi nulletc # tiksi@layla ~ $ curl -vv -s "http://example.com/uid=${thisisgone}-$(date)`pwd`\n\x00\x00nulletc\0xb" 2>&1|egrep GET [09:47:26] > GET /uid=-Thu Apr 23 09:47:41 EDT 2015/home/tiksi\n\x00\x00nulletc\0xb HTTP/1.1
- vog 11y agoEven single quotes need some additional escaping, see my other comment: https://news.ycombinator.com/item?id=9427820 https://news.ycombinator.com/item?id=9427820
- vog 11y agoAdding double quotes is risky with regard to "`", "$" and other special shell characters. Adding single quotes is safer, but will fail if the argument itself contains single quotes. To my knowledge, the correct shell escaping is to surround your argument with single quotes, and before doing that, replace each contained single quote ' with the following sequence (1): '\'' Alternatively, you can use (2): '"'"' Both sequences work the same way: First, terminate the single-quoted string. Then, add an escaped single quote, either with backslash (1) or by encapsulating into double quotes (2). Finally, start an new single-quoted string.
- Tiksi 11y agoAs far as I know, escaping single quotes inside single quotes doesn't work in bash: tiksi@emperor:~$ curl 'http://\'test' > > > >^C tiksi@emperor:~$ curl 'http://\'test'' curl: (6) Could not resolve host: \test tiksi@emperor:~$ Anything inside single quotes is treated literally, so no escapes work.( Unless you're doing $'.stuffhere', but that's a whole other can of worms). The double quotes around single quotes does work though.
- vog 11y ago> escaping single quotes inside single quotes That's why you have to escape single quotes with '\'' rather than just \' As I said, you first have to terminate the single-quoted string, then add the single quote, then start a new single-quoted string. In your example, my variant (1) leads to: curl 'http://'\''test' And my variant (2) leads to: curl 'http://'"'"'test'
- Tiksi 11y agoAh, I misread your first post as meaning '...\'...' instead of literally '\''. I've always used the '"'"' method, or "$(sed -r 's/([allthespecialchars])/\\\1/g')" , but '\'' is much cleaner. I have found the terminate and escape quite useful for color codes though 'string'\e[31m'red'"$var"'morestring', not sure how I never thought to use it for '\'', but thats getting added to my toolbox :)
- amelius 11y agoDoesn't work with tcsh. Does anybody know how to escape curly braces on tcsh?
- deleted 11y ago[deleted]
- mrfusion 11y agoI'd love to see things like this built for lots of complex command line tools. I think awk would be really useful.
- jaryd 11y agoYeah, awk can be tricky. This tutorial[0] was posted awhile back and I bookmarked it because I found it to be very useful. Check it out if you haven't seen it. [0] http://ferd.ca/awk-in-20-minutes.html http://ferd.ca/awk-in-20-minutes.html
- rafaqueque 11y agoGood idea. It's quite difficult to remember all those parameters and command structure. Thanks, bookmarked.
- laumars 11y agoFYI, the command line already comes equipped with tools to lessen your needed for remembering the various different flags: # invoke the curl manual: man curl and # display a basic help file: curl -h
- 5h 11y agoGood timing, I was just after something to like this to include in some API docs i'm handing over.
- Gonzih 11y agowhy not just man curl?
- kstrauser 11y agoThere's a lot of benefit in something that can properly escape data, for instance. I'm totally comfortable with curl but sometimes physically typing the command line is harder than deciding what should go in it.
- euphemize 11y agoCool, gimme a field to add a custom header (e.g. "Authorization" is pretty common) and I'll use it!
- Tiksi 11y agoKinda defeats the purpose of using the tool, but headers in curl are pretty simple: curl http://example.com -H 'Authentication: root' -H 'Password: p4ssw0rd'
- seanp2k2 11y ago-H is for headers; yes, but basic auth is actually the base64-encoded string of user:pass , so if constructing it manually you'd want to do something like curl -H "Authorization: Basic $(echo -n 'user:pass' |base64)" http://whatever http://whatever . Curl provides a shortcut for this as --user; e.g. curl --user name:pass http://example.com http://example.com Try it yourself with -vvv to see all the headers from both ends. Ref: http://curl.haxx.se/docs/httpscripting.html#Basic_Authentication http://curl.haxx.se/docs/httpscripting.html#Basic_Authentica... http basic auth protocol: http://en.m.wikipedia.org/wiki/Basic_access_authentication http://en.m.wikipedia.org/wiki/Basic_access_authentication
- Tiksi 11y agoYou can also use curl --negotiate -u : for kerberos (provided curl is built with it and spengo). curl supports quite a few less used auth methods, but OP mentioned custom headers, not basic auth per se, (thats why I used Authentication instead of WWW-Authenticate or Authorization as an example)
- tuxone 11y agohere you are ;)
- laumars 11y agoWhile I appreciate the idea and the work that's gone into this site, sadly it seems too basic to be of much use. It only supports half a dozen flags - all of which are easy to use normally anyway. It's missing user agent, headers, cookies, etc. The latter two being items that could be particularly tricky for the "curl novice". Instead I'd probably recommend people use Chrome/Chromium's developer tools which can export HTTP requests as curl commands: https://coderwall.com/p/-fdgoq/chrome-developer-tools-adds-copy-as-curl https://coderwall.com/p/-fdgoq/chrome-developer-tools-adds-c...
- guava 11y agoIt does seem to support custom headers, but as you stated doesn't support user agents, cookies, etc.
- laumars 11y agoHeaders were added after my comment: https://news.ycombinator.com/item?id=9426493 https://news.ycombinator.com/item?id=9426493
- tuxone 11y agoYes, the site is very basic, it's just an "Hello world" experiment in AngularJS. Though I was thinking someone could find it useful and I put it online. If the interest grows I'll probably add more features and integrations.
- joemccall86 11y agoSeems pretty helpful, though for most of my endpoint testing I've switched to httpie[1], and my teammates have followed. The only exception is when I need to load-test a service real quick, and curl can make requests much faster than httpie. [1] https://github.com/jakubroztocil/httpie https://github.com/jakubroztocil/httpie
- vially 11y agoI love httpie as well but recently I switched to bat [0] which offers pretty much the same thing but is written in Go so is deployed as a single binary. [0] - https://github.com/astaxie/bat https://github.com/astaxie/bat
- ecaron 11y ago@tuxone - Any chance of opening this up to accept PRs for adding new exposure to curl features (like adding headers)?
- johns 11y agoThis is really cool. You could tie the output to one of my projects: embedcurl.com This also makes me want to go back and add Copy as curl to hurl.it.
- ripkirby 11y agoRead the man pages
- VeejayRampay 11y agoJust for the info, Chrome (and possibly other browsers as well) allows to build cURL commands from any network calls with a right-click on a HTTP call in the Network tab.
- fideloper 11y agoWhat I really want is for requestb.in (and friends) to generate a cURL CLI command for me, just like Chrome developer tools does. This would be useful for things like grabbing a test Stripe webhook sent to requestb.in and sending it to your local dev server. (I think there are some things you can host yourself to capture and replay HTTP requests, however - I can't remember what they are)
- seanp2k2 11y agoChrome dev tools network tab -> right click on request -> copy as cURL is one of my favorite features of chrome dev tools. Another favorite of mine is the Tamper extension, which lets you edit js / css and reload the page, having your edited versions served from mitmproxy: https://chrome.google.com/webstore/detail/tamper/mabhojhgigkmnkppkncbkblecnnanfmd?hl=en https://chrome.google.com/webstore/detail/tamper/mabhojhgigk...
- kstrauser 11y agoI'm a huge fan of "Paw" for OS X (https://luckymarmot.com/paw https://luckymarmot.com/paw). After you construct your query, it generates the equivalent code for curl, Objective-C (NSURLConnection or AFNetworking), Python, jQuery, or several others. It also now integrates with Mashape so you can download preconstructed libraries of API calls. Disclaimer: I have no connection with Paw's developers - I'm just a very happy user.
- edge17 11y agovery cool, thanks for sharing this
- Aldo_MX 11y agoSadly only for OS X...
- spdustin 11y agoI am too. Especially the ability to configure "environments" to collect variables you'll reuse, the export options (copy as curl, as jQuery.ajax, etc) and the oauth workflow tools built in. Paw is a wildly useful tool. - another unpaid but wholly satisfied user
- niix 11y agoNice, this is really helpful.
- pkulak 11y agoI'm a big fan of right clicking on the request in the Chrome developer console and selecting "Copy as cURL". Obviously only works if you're doing browser stuff, but super helpful nonetheless.
- zachrose 11y agoIndeed. I've been looking for an HTTP library that will let me get curl representations of requests for debugging/collaboration. Something like: req = require('library').request(url, handler); console.log(req.toCurl()); Haven't found one yet.