Blog

Find out about the latest from Cloudmersive.

Testing Cloudmersive APIs with cURL
6/5/2024 - Brian O'Neill


API graphic

Whether we’re testing API calls to a Cloudmersive Public Cloud, Private Cloud, or Managed Instance endpoint, cURL offers a convenient solution.

Below, we’ll learn more about what cURL is and how we can use it to test Cloudmersive APIs.

What is cURL?

cURL stands for “Client URL”.

At a high level, cURL is a command-line utility that allows us to send and receive data using URL syntax. We can use cURL to transfer data using a wide range of different protocols, including HTTP, HTTPS, FTP, FTPS, SCP, SFTP, LDAP, and more.

What is cURL API Testing?

When we test an API with cURL commands, we send HTTP requests directly from our terminal or command prompt to an API endpoint.

This lightweight testing method is used to confirm the APIs our applications rely on are modifying and/or returning data the way we expect them to.

It’s worth noting that using cURL commands to test Cloudmersive APIs is extremely similar to using Postman for the same purpose. The major difference is that Postman offers a user-friendly GUI with plenty of advanced features. If you’d prefer to go that route, feel free to check out a different post on that subject.

Example: Testing the Cloudmersive Basic Virus Scan API with cURL Commands

Preformatted cURL command examples are available to all Cloudmersive customers through the Management Center in the Cloudmersive Account Portal.

To test any Cloudmersive API with cURL commands, we first need to navigate to the Docs & Examples Documentation page from the Management Center.

Here, we’ll find code examples we can use to structure Cloudmersive API calls in a variety of common programming languages.

Find cURL Command Examples

First, let’s select the cURL option from the Programming Language list. Right after that, we can select the Virus Scan API option from the API list. This will bring up cURL command examples for each iteration of the Cloudmersive Virus Scan API in Step 2 – Get Started with Example Code.

Find the Basic Virus Scan API Iteration

If we type “Scan a file for viruses” in the Search APIs field, we’ll bring up cURL examples for the Basic Virus Scan API iteration right away. Alternatively, we can skip the search and simply scroll this list until we find that option.

Format the Examples for our OS

These are the cURL command examples we should see:

curl --location --request POST 'https://api.cloudmersive.com/virus/scan/file' \
--header 'Content-Type: multipart/form-data' \
--header 'Apikey: YOUR-API-KEY-HERE' \
--form 'inputFile=@"/path/to/file"'

It’s important to note that the above default examples are formatted for Unix-like command terminals.

If we want to reformat our commands for a Windows command prompt, we’ll need to replace backslashes with carets, and we’ll need to replace single quotes with double quotes.

Below, we’ll find the same examples formatted correctly for a Windows command prompt:

curl --location --request POST "https://api.cloudmersive.com/virus/scan/file" ^
--header "Content-Type: multipart/form-data" ^
--header "Apikey: YOUR-API-KEY-HERE" ^
--form "inputFile=@\"C:\path\to\file\""

Now we’ll break down each line of our example commands and determine what information we need to complete our own request.

Endpoint URL
curl --location --request POST 'https://api.cloudmersive.com/virus/scan/file' \

The URL shown above is the default Cloudmersive Public Cloud endpoint. Since we’re testing the Basic Virus Scan API in this example, we’re making a POST request to that endpoint.

If we want to make POST request to our Managed Instance or Private Cloud endpoint instead, we’ll need to replace this URL with our own endpoint URL. Depending on our subscription, we can also test a wide range of Public Cloud endpoints. We’ll find these by navigating to the API Endpoint page from our Management Center.

Request Headers
--header 'Content-Type: multipart/form-data' \
--header 'Apikey: YOUR-API-KEY-HERE' \

Our cURL request has two separate headers. The first header defines the HTTP content type (in this case, multipart/form-data), and the second header captures our API key to authorize the request.

We can copy an API key from the API Keys page in the Cloudmersive Account Portal and paste that into our second header, replacing the YOUR-API-KEY-HERE placeholder text.

Request Form
--form 'inputFile=@"/path/to/file"'

The form line captures the data we’re sending to the API endpoint in our POST request. We can replace the ”/path/to/file” example with the path to whichever file we’ve decided to use in our test.

Carrying Out our cURL Test

Once we’ve properly formatted and filled out our cURL request, we can paste the cURL commands into our terminal or command prompt. This should execute our cURL request right away.

A successful Basic Virus Scan API test with a clean file will return the following response:

{"CleanResult":true,"FoundViruses":null}

And that’s all there is to it!

We can easily use cURL examples to test any API on the Cloudmersive API platform.

Need Additional Help?

If you have any additional questions about testing Cloudmersive APIs with cURL command examples, please feel free to reach out to a member of our support team.

800 free API calls/month, with no expiration

Get started now! or Sign in with Google

Questions? We'll be your guide.

Contact Sales