Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Online curl command line builder (curlbuilder.com)
96 points by tuxone on April 23, 2015 | hide | past | favorite | 44 comments


While 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-c...


Yes, 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.


It does seem to support custom headers, but as you stated doesn't support user agents, cookies, etc.


Headers were added after my comment:

https://news.ycombinator.com/item?id=9426493


Seems 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


I 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


I'm a huge fan of "Paw" for OS X (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.


I 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


very cool, thanks for sharing this


Sadly only for OS X...



httpie is awesome, but in some environment all you have is curl.


Nice 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).


Thank you for you feedback, does adding double quotes solve the problem?


Single 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


Even single quotes need some additional escaping, see my other comment: https://news.ycombinator.com/item?id=9427820


Adding 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.


As 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.


> 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'


Ah, 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 :)


I'd love to see things like this built for lots of complex command line tools. I think awk would be really useful.


Yeah, 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


I'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.


Indeed. 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.


Just 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.


What 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)


Chrome 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/mabhojhgigk...


Good idea. It's quite difficult to remember all those parameters and command structure. Thanks, bookmarked.


FYI, 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


Good timing, I was just after something to like this to include in some API docs i'm handing over.


This 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.


@tuxone - Any chance of opening this up to accept PRs for adding new exposure to curl features (like adding headers)?


Cool, gimme a field to add a custom header (e.g. "Authorization" is pretty common) and I'll use it!


Kinda defeats the purpose of using the tool, but headers in curl are pretty simple:

    curl http://example.com -H 'Authentication: root' -H 'Password: p4ssw0rd'


-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 .

Curl provides a shortcut for this as --user; e.g. curl --user name:pass 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_Authentica...

http basic auth protocol: http://en.m.wikipedia.org/wiki/Basic_access_authentication


You 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)


here you are ;)


Doesn't work with tcsh.

Does anybody know how to escape curly braces on tcsh?


why not just man curl?


There'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.


Nice, this is really helpful.


what 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.


I 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.


Read the man pages




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: