cURL

Client URL (cURL) serves as a command-line tool and library for sending requests to and receiving responses from servers through network protocols. It is often used to troubleshoot or test responses from servers and APIs.

cURL can send and receive data using different protocols such as HTTP, HTTPS, FTP, and others. You can access cURL through your command prompt, where you can directly issue requests and retrieve data from servers. cURL provides options and flags to configure request parameters and headers, such as authentication credentials, cookies, and query parameters. The command prompt displays the server’s response by default, including a status code, headers, and response body, which you can filter using cURL’s flags.

The format for sending and receiving data can vary, including form data, JSON payloads, files, and others. The response formats include JSON, XML, HTML, and plain text. cURL includes SSL/TLS support, allowing for secure communication over HTTPS.

Examples

Below are a few examples of cURL requests from the DigitalOcean API. Each example references an environment variable named $DIGITALOCEAN_TOKEN that contains the API token used to authorize requests to the API.

The following GET request retrieves account information about the current user:

curl -X GET \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
  "https://api.digitalocean.com/v2/account"

The following POST request creates a new app on App Platform using an inline app spec:

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
  "https://api.digitalocean.com/v2/apps"
  -d '{"spec":{"name":"web-app","region":"nyc", \
  "services":[{"name":"api","github":{"branch":"main",\
  "deploy_on_push":true,"repo":"digitalocean/sample-golang"}, \
  "run_command":"bin/api","environment_slug":"node-js", \
  "instance_count":2,"instance_size_slug":"basic-xxs", \
  "routes":[{"path":"/api"}]}]}}'

The following DELETE request deletes the specified app on App Platform:

curl -X DELETE \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
  "https://api.digitalocean.com/v2/apps/4f6c71e2-1e90-4762-9fee-6cc4a0a9f2cf"

To learn more about cURL, see their official documentation.

Delete apps from your app platform.