Programming

curl

What is curl?

curl is the command of Daniel Stenberg's cURL project. The first open release is near 1997. A URL goes inside the name. The command connects to that address and prints the bytes that come back. It is mostly for HTTP and HTTPS, but it is not HTTP itself. HTTP is the name of the rule. curl is the tool that talks by that rule. A browser turns HTML into a page. curl shows the text as it is.

What is curl used for?

curl is for checking an API, seeing a header, and downloading a file with a command.

  • Reading one address's response
  • Seeing only the headers
  • Sending JSON and receiving the answer
  • Downloading a file into a folder

What can you do with curl?

With curl you send GET and POST. You see the status and the body. It does not draw a button and it does not run JavaScript. If a page fills only with a script, curl can show empty or half text. If a token or a password stays inside the command, it can remain in the history.

Is curl hard to learn?

Opening one address is easy. The difficulty is the header and the method. Sending a POST as a GET does another job on the server. A certificate error stops the connection. Do not turn that check off, because the name may be another site. If the response is large, the terminal fills up.

Advantages and limits

Advantage: the response is visible without a browser, the command goes into a script, and a header is read separately. Limit: it does not walk the page like a person. curl is not HTTP itself, and it is not a browser.

Basic ideas

The address says where it goes. The method says what you want. The response is a status and a body.

  • curl without an address goes nowhere
  • -I asks for the header only
  • -d sends a body
  • Status 200 means it was received

A short example

This command prints the response text of one address. It does not open the page in a window.

curl https://nibrascode.com

Common questions

  • Are curl and a browser the same? No. A browser draws the page. curl shows the text of the response.
  • Are curl and HTTP the same? No. HTTP is the name of the rule. curl is the command that sends a request by that rule.
  • Does JavaScript run? No. curl does not run a script. It only shows the text that arrives.