What Is CURL

What is curl, and how does it work?

  • Client URL (curl) is a command line tool used to transfer data. Curl uses URLs to specify where a request is sent, followed by the data to be transferred.
  • Curl is widely used across the web and is highly portable. It is compatible with almost every operating system and supports many protocols, including HTTPS, FTP, SMPT, POP3, and more.
  • In terms of APIs, curl is great for testing endpoints.
  • A curl request, in its most basic form, looks like this: curl [URL]
  • By default, curl requests that only specify a URL are sent as GET requests. So the example above would return the HTML source for the specified URL.
  • There are over 200 curl commands that can be used. Most follow this basic format: curl [option] [URL] . You can run ‘curl –help’ or simply ‘-h’ in your command line to get a list of all the available curl commands.
  • curl can be used for authentication and sending all the usual HTTP method requests (GET, POST, DELETE, etc.) . This is done using the -X option. For example, a POST request syntax is as follows: curl -X POST [URL]

Other commonly used options are,

  • -I : This command returns HTTP header fields such as Content-Type, Date, etc.
  • -v: The ‘verbose’ command, which returns data to tell you everything that happened when you ran the curl request, including connection info and headers.
  • -o : -o is followed by a specified file and redirects the returned data there instead of the standard output.
  • -H: Adds additional HTTP Headers to a request. It is followed by the header name and value in enclosed quotes, e.g. Curl -H ‘[Header name: value]’ [URL]