acurl is a handy alias we use here at Cloudant that allows you to
curl Cloudant URLs without having to enter your username and password for every HTTP request. That means a simple
GET to a database no longer needs to be written as
https://<username>:<password>@<username>.cloudant.com/foo but instead you can just use
Not only does this cut down on annoyingly long URLs, but the
acurl alias is also more secure. It prevents someone from reading your password over your shoulder as you type, and importantly, it makes sure your password isn’t sent in plain text over the network by enforcing HTTPS.
All it takes is three simple steps:
1) First we base64-encode your Cloudant username and password:
python -c 'import base64; print base64.urlsafe_b64encode("<username>:<password>")' <OUTPUT-OF-BASE64>
Note: Remember that your password is still stored in plain text on your computer; base64-encoding is not encryption!
2) Now we create an alias for curl that includes these credentials so we don’t have to enter them every time we write a curl command.
Add this line to your
alias acurl="curl -s --proto '=https' -g -H 'Authorization: Basic <OUTPUT-OF-BASE64>'"
This alias adds an Authorization header instead of including the authorization credentials in the URL you enter on the command line. It also forces the use of HTTPS which we strongly recommend over plain HTTP as it encrypts your data and credentials in transit and helps you be sure you’re connecting to our systems.
3) Now start a new shell or run
source ~/.bash_profile (or
~/.bashrc if you used that) to make the alias functional.
And that's it!
Now let's make sure everything is set up correctly. Go ahead and run:
If you get the list of your databases back, awesome!
acurl is set up and ready to go. Happy coding!
If you need more help, watch the video below to see how to set up pre-authenticated cURL or follow the step-by-step instructions in this tutorial.