Use Of Curl

What is the curl command? Learning and testing APIs with …

cURL, which stands for client URL, is a command line tool that developers use to transfer data to and from a server. At the most fundamental, cURL lets you talk to a server by specifying the location (in the form of a URL) and the data you want to send. cURL supports several different protocols, including HTTP and HTTPS, and runs on almost every platform. This makes cURL ideal for testing communication from almost any device (as long as it has a command line and network connectivity) from a local server to most edge devices.
The most basic command in curl is curl. The curl command is followed by the URL, from which we would like to retrieve some kind of data. In this case, it would return the html source for
Underlying the curl command is the libcurl development library, which has bindings for almost any codebase.
cURL is also the name of the software project, which encompasses both the curl command-line tool and the libcurl development library.
To try out the commands in this article, you need a command shell and internet access. We are going to be using the NASA APOD (Astronomy Picture Of the Day) API to create some examples. This API is open source but you will need to sign up for a developer key, which takes just a minute to get signed up.
Why use curl?
So, why should you use cURL? Consider these benefits of this software project:
It is highly portable. It is compatible with almost every operating system and connected device.
It is useful for testing endpoints, to check if they are working.
It can be verbose, providing details of exactly what has been sent/received, which is helpful for debugging.
It has good error logging.
It can be rate limited.
Sending API requests
We can use curl to send API requests. Each request is generally made up of four main parts:
An endpoint, which is the address (URL) to which we are sending the request.
An HTTP method. The most common methods used are GET, POST, PUT and DELETE.
GET is used to retrieve a resource from a server. This could be a file, information, or an image.
POST is used to send information to the server.
PUT can be used to create or update a resource. This could be used to create or update a record in a database or update the contents of a file.
DELETE is used to delete a resource such as a database entry.
These actions for these methods are the recommended actions, but it’s up to the API specification and implementation to define what exactly happens.
Headers, which contain metadata about the request, such as content type, user agent, and so on.
Body, which is the message body and contains the data that we want to send, if any. Generally, the body is used with POST and PUT methods.
curl command options
There are over two hundred curl options. You can see some of them by typing curl -h in a terminal. The most commonly used command options include these:
-I returns only the HTTPS headers
curl –request GET ‘&date=2020-01-01′ -I
This command will return header fields such as Date, Content-Type etc
-v is the verbose option
curl –request GET ‘NASA_API_KEY&date=2020-01-01’ -v
This verbose command will show you everything that happens when you run the curl command, from connection to the headers and any data returned. Here we also get the description of the image that is being returned by the request, along with the image url.
-o stores the output in a file
curl –request GET ‘NASA_API_KEY&date=2020-01-01’ –output curloutput
Combining curl with other CLI commands
Combining curl with other cli commands can be really handy in situations where you want to use the output of a command as the input to a curl command or vice versa.
As an example, you could see if a webpage contains a certain piece of text using curl and grep.
Here is an example of using curl and Python to extract the image link from a request to the NASA API and display it in the Preview app (MacOS only):
curl –request GET “NASA_API_KEY&date=2020-01-01” -s | python3 -c “import sys, json; print(()[‘url’])” | xargs curl -o && open -a Preview
In this example we use curl to make a GET request on the Nasa API endpoint. This returns json data, which we use in a small Python script to extract the url of the image. We then use the curl command to get the image and open it using Preview on the mac.
You don’t have to use the command line curl to make API requests. You can use a number of different tools to interact with an API, such as HTTPie, Postman, and Rest Client in VS Code.
HTTPie is a command-line HTTP client that is touted as more friendly to users. It also includes a more expressive, color-coded UI. They have an online version, which is really neat.
Postman is a UI-based client for all things related to API development, and it’s arguably one of the most popular. Postman is very powerful.
You can generate and execute curl commands from within Postman. To generate curl commands, you can enter the request URL and parameters, and then click on the code option on the right-hand side:
A box is displayed with the option to select from a number of languages, including curl. Select curl to see the generated curl command.
Postman gives you a history of all the requests that you’ve built and even data-stamps them, which can be nice for collecting data points or references as you work with an API. Think of it as the client taking notes for you.
Rest Client in VS Code
Rest Client for VS Code is probably one of my favorite tools for executing curl commands. It’s lightweight and has good syntax highlighting. It’s a really useful add-on to do some quick curl requests from within VS Code.
You can simply type in your curl command and a ‘send request’ option will appear above.
After you click send request, another tab opens with the response.
Summary and Next Steps
In this article, we introduced you to the basic curl command and its most useful options. We also mentioned only a handful of the tools that are available to help you get started with cURL. Now you can begin using cURL to test your endpoints and troubleshoot your applications.
To find out more about APIs and API Management, check out the following articles and videos available on IBM Developer:
API Fundamentals
What is a REST API
This article was originally authored by Amara Graham and published in April of 2019.
cURL: What is It and How do I Use It? | pair Networks Blog

cURL: What is It and How do I Use It? | pair Networks Blog

What is curl?
cURL, often just “curl, ” is a free command line tool. It uses URL syntax to transfer data to and from servers. curl is a widely used because of its ability to be flexible and complete complex tasks. For example, you can use curl for things like user authentication, HTTP post, SSL connections, proxy support, FTP uploads, and more! You can also do simple things with curl, such as download web pages and web images. Read on to find out if you should use curl, and if so, common use cases that will get you started.
Should You Use curl?
Whether or not you should use curl depends on your goals. For simpler goals, you may want to check out wget. curl is great for complex operations since it is scriptable and versatile. However, wget is easier to understand and more user-friendly, so we recommend using it for simpler tasks.
curl Protocols
curl has many different supported protocols. However, curl will use HTTP protocol by default if no protocol is provided. For example, if you run the following example, it would download the homepage of
You can call a specific protocol by prefacing the URL with the protocol name.
curl The example above uses the HTTP protocol. If you want to use a different protocol, switch HTTP out for another. For example, if you wanted to use the FTP protocol, it would look like this:
curl curl will also try different protocols if the default protocol doesn’t work. If you give it hints, curl can guess what protocol you want to use.
For example, if you wrote the following command, curl would be able to intelligently guess that you wanted to use the FTP protocol.
Here’s a list of curl supported protocols:
Basics: How to Use curl
We touched on how to use curl protocols briefly, which may have given you some idea on how to use curl. At its most basic, curl tends to follow this format:
curl [option] [url]
You can find a list of possible options on the curl documentation site. Options will direct curl to perform certain actions on the URL listed. The URL gives curl the path to the server it should perform the action on. You can list one URL, several URLs, or parts of a URL, depending on the nature of your option.
Listing more than one URL:
curl -O -O Listing different parts of a URL:
page1, page2, page3}
Saving URL to File
You can also use curl to save the content of the URL to a file. There are two different methods for doing this: the -o and the -O method. When you use the -o option, you can add a filename that the URL will be saved as. A command using the -o option would look something like this:
curl -o Notice that the filename the URL will be saved in is placed between the -o option and the URL.
The -O method allows you to save the file under the same name as the URL. When using the -O option, no filename is required between the option and the URL. Instead, the command will look something like this:
curl -O Continuing a Download
If your download is stopped, you can restart it again with a simple curl command. It’s very simple, all you need to do is rewrite the command with the addition of the -C option.
If you were saving a URL, but the process was halted, you can restart the process by typing in the following:
curl -C -O This would pick the process back up where it had halted before.
Specify Time Frame for Download
Download files before or after a certain time by using curl. To do this, use the -z option, then list the date.
curl -z 25-Jan-18 The -z option will search for files after the designated time frame by default. To search for files before the time listed, you can add a dash in front of the date. It will look like this:
curl -z -25-Jan-18 Showing curl Output
curl will often not show any output after you have executed a command, which can be frustrating if you are trying to learn the ropes. The good news? curl has an option that allows you to view curl as it works.
You just need to add a -v to the command to view curl’s internal runnings as it executes. This can be especially helpful when you receive a response from curl that you didn’t anticipate. By viewing curl with -v, you can see what curl is actually doing behind the scenes. Simply run the command to turn it on.
Here’s an example of what a command with the -v option would look like:
curl -v If you get tired of seeing the internal workings of curl, you can also turn this feature off by using the –no-verbose option. Just switch the -v option out for –no-verbose, and curl will stop showing the internal process.
curl –no-verbose curl in Review
curl is a powerful, flexible tool. The commands touched on here were only the tip of the iceberg – curl has the ability to work with a multitude of protocols and, while we only touched on HTTP-specific options. Stay tuned for more blog posts about curl in the future. You can be notified as soon as a new blog post comes out.
If you like the idea of curl, but think it might be too complex for you, check out our article on using wget.
command linecurl
What is cURL?: A Complete Guide | Career Karma

What is cURL?: A Complete Guide | Career Karma

Application Programming Interfaces (APIs) are an essential part of the web. These tools allow you to interact with other platforms.
Find Your Bootcamp Match
Career Karma matches you with top tech bootcamps
Get exclusive scholarships and prep courses
For example, you can use the Twitter API to post Tweets or display a list of Tweets on your timeline. You can use the Airtable API to access your spreadsheets on Airtable and add new records. But, how do you actually interact with APIs?
One of the most common ways to interact with an API is through cURL, a command line tool that allows you to make web requests. It’s likely most APIs you’ve seen in your history as a developer will have included at least some documentation on how to use cURL with their API.
In this guide, we’re going to discuss what cURL is and how you can use it to make a web request. We’ll also walk through a few basic curl commands to help you get started.
What is cURL?
cURL stands for “client URL” and is a command line tool that allows you to interact with websites. You can use it to make any type of web request. This means you can use cURL to get information from APIs, download webpages or submit data to an API.
cURL comes installed on most UNIX-based operating systems, so unless you are running an Apple II, then you probably already have the package installed. When you use cURL as a command, you don’t need to capitalize the term: just use the command curl.
How to Make a Request Using cURL
In this tutorial, we’re going to discuss how to use cURL to retrieve information from the Airtable API. This API allows you to view, create and amend records in an Airtable database, which is similar to a spreadsheet. Our Airtable document contains a list of teas with some tasting notes.
The Airtable API provides two options you can use to interact with their API: cURL or JavaScript. Of course, we’re going to focus on the cURL option in this tutorial.
Make a GET Request Using cURL
To make a cURL web request, we only need to specify “curl”, followed by the URL that we want to retrieve. If we want to make a GET web request to the Airtable API, we could use this command:
curl ”
When this command is executed, the following is returned:
{“error”:{“type”:”AUTHENTICATION_REQUIRED”, “message”:”Authentication required”}}
Our cURL command has successfully made a web request! The problem is that we haven’t yet specified an API key, which we must use to authenticate ourselves. To do so, we are going to follow the instructions on the Airtable API and specify an “authorization” header:
curl ” -H “Authorization: Bearer YOUR_API_KEY”
When we run this command with an API key, the following is returned:
“Drink”:”Black Decaf Tea”,
“Date”:”2020-05-24T10:03:38. 000Z”},
“createdTime”:”2020-05-24T10:03:38. 000Z”]}
As you can see, cURL has returned a list of the records in our database. Right now, we only have tasting notes for one tea, but that’s all we need to show that our cURL command has worked.
Make a POST Request Using cURL
cURL also supports making HTTP POST requests. This allows you to submit data to a web server which will be processed by that server. In the case of the Airtable API, a POST request allows you to add a record to a database. Airtable gives us the following command as an example:
curl -v -X POST \
-H “Authorization: Bearer YOUR_API_KEY” \
-H “Content-Type: application/json” \
–data ‘{
“records”: [
“fields”: {
“Drink”: “Darjeeling”}}, ]}’
There’s a lot going on in this command, so let’s break it down:
-v tells cURL to show us all the details of the output. -X POST tells cURL to make a POST request. is the URL to which we are sending our post request. -H allows us to specify headers for our web request, which store additional data such as our API key and the type of content we are sending. –data is where we specify the data we want to send to the web server.
Executing this command returns the following:
“id”: “recyPfUXJUP1HH03a”,
“Drink”: “Darjeeling”,
“Date”: “2020-05-24T10:03:38. 000Z”},
“createdTime”: “2020-05-24T10:03:38. 000Z”}, }
Our command worked! We successfully used cURL to make a POST request to the Airtable API.
Wrapping Up
cURL may not be the most intuitive tool in the world, but it does make an excellent candidate for interacting with APIs.
There are a number of tools out there you can use instead of cURL, such as Postman or Insomnia. These tools provide a graphic user interface that makes it easy to customize your web requests. In addition, if you’re building a web app, you’ll probably want to make a web request using code in a language like Python.
However, the main advantage of using cURL is that it helps you figure out how to structure your web requests before you add them to your application. You can try out different methods and make sure a request is valid before actually coding it into your application.
If you want to learn more about how the curl command works, check out the man page on curl by running man curl in your Linux command line.

Frequently Asked Questions about use of curl

Why do we use cURL?

curl is a widely used because of its ability to be flexible and complete complex tasks. For example, you can use curl for things like user authentication, HTTP post, SSL connections, proxy support, FTP uploads, and more! You can also do simple things with curl, such as download web pages and web images.Jan 26, 2018

What is cURL and how do you use it?

cURL stands for “client URL” and is a command line tool that allows you to interact with websites. You can use it to make any type of web request. This means you can use cURL to get information from APIs, download webpages or submit data to an API.Jun 25, 2020

Where is cURL command used?

curl is a command line tool to transfer data to or from a server, using any of the supported protocols (HTTP, FTP, IMAP, POP3, SCP, SFTP, SMTP, TFTP, TELNET, LDAP or FILE). curl is powered by Libcurl. This tool is preferred for automation, since it is designed to work without user interaction.May 15, 2019

Leave a Reply

Your email address will not be published. Required fields are marked *