Authorized curl, a.k.a acurl

By Samantha Scharr

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> but instead you can just use https://<username>

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:

Create an account and try this with your own Cloudant account

1) First we base64-encode your Cloudant username and password:

python -c 'import base64; print base64.urlsafe_b64encode("<username>:<password>")'   


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 ~/.bashrc or ~/.bash_profile:

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:

acurl https://<username>

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 Watch video video below to see how to set up pre-authenticated cURL or follow the step-by-step instructions in this Try for Yourself tutorial.

Sign Up for Updates!

Recent Posts