Blog

- March 25, 2015

The venerable cURL command-line tool to interact with URLs throughout various protocols just turned 17 last week. Daniel Stenberg, the creator of cURL, is still to this day the leader of the project, showing an amazing track record, and gives an interesting overview of the cURL story on his blog. Daniel started cURL when Open Source wasn’t really a thing just yet — the term OSS was actually coined the same year, in 1998, when the project was created. Over those 17 years, 1200 persons contributed to the project!

On behalf of the Restlet team, we wish cURL a very happy birthday, and congratulate Daniel for this achievement!

curl-17-birthday

To further celebrate this anniversary, let’s use cURL to invoke APISpark hosted APIs!

If you follow one of our tutorials on creating your first API from scratch, exposing a SQL database or a Google Spreadsheet in a web API, you’ll want to test your API: once it is published, you can invoke your web API with cURL.

You’ll need to take note of your API endpoint URL, and the Basic Auth credentials, that you can find in the Overview tab, under the Endpoints section, as you can see in the screenshot below. We’re going to pass them to cURL via the command line.

endpoint-credentials

So for instance, if you have a simple “car” resource in your API, you’ll be able to list all the available cars with:

curl --user 
       ceae62c6-fa78-4b95-a60f-291b9d0bb926:23cfec49-9ad4-43c4-9142-595f9c224403 
     -H "Accept: application/json" 
     -X GET https://mysupercoolapi.apispark.net/v1/cars

If there’s no car yet in your garage data store, cURL will return an object with an empty list:

{"list":[]}

Let’s add a new car to the list, with the following command:

curl --user 
       ceae62c6-fa78-4b95-a60f-291b9d0bb926:23cfec49-9ad4-43c4-9142-595f9c224403 
     -H "Content-Type: application/json"
     -X POST 
     -d '{"name": "Tesla"}' https://mysupercoolapi.apispark.net/v1/cars

The APISpark server will reply with the details of the created resource:

{"name":"Tesla","id":"374d0541-d179-11e4-87fa-49a8ffa9b046"}

And if you make another GET call on the collection endpoint, you will see it being returned in the list:

{"list":[{"name":"Tesla","id":"374d0541-d179-11e4-87fa-49a8ffa9b046"}]}

Next, you might be deciding to sell your Tesla car? So let’s remove it from the garage:

curl --user 
       ceae62c6-fa78-4b95-a60f-291b9d0bb926:23cfec49-9ad4-43c4-9142-595f9c224403 
     -H "Accept: application/json" 
     -X DELETE https://mysupercoolapi.apispark.net/v1/cars/374d0541-d179-11e4-87fa-49a8ffa9b046

Your garage is now empty, thanks to cURL and Daniel Stenberg, time to shop for your new car!