By benqzq
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.
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!
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.