Question

Working with long DIgitalOcean API commands

I have this very long and heavy DigitalOcean API command to rebuild droplet (I have a mistake there which I’m trying to figure out but it’s just for example to longevity problem).

I think it would be better of to work with multi-lined, because in one long row it’s just extremely uncomfortable to maintain. For example, look how long this one liner is:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer 81206074d17245ba5d106d788b9edfea9947b1712ab47efgd6888e67f2e79957" -d '{"type":"rebuild","image":"ubuntu-16-04-x64"}' "https://api.digitalocean.com/v2/droplets/3164450/actions" 

Maybe it’s best to do:

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer 81206074d17245ba5d106d788b9edfea9947b1712ab47efgd6888e67f2e79957" \
 -d '{"type":"rebuild","image":"ubuntu-16-04-x64"}' \
"https://api.digitalocean.com/v2/droplets/3164450/actions" 

Maybe something extra (a bash function? a Bash script?)

Please share any tip, thanks!


P.S. I’ve already deleted that token, I just gave it for the example here.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Breaking it up into multiple lines definitely makes it more readable and easier to understand. You might also be interested in looking at the doctl command line tool. The same command using it would be:

doctl compute droplet-action rebuild 3164450 --image ubuntu-16-04-x64

If you’re are using it in a script, you can also pass --output json in order to have the same JSON response you would receive using cURL.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.