Curl is a command-line tool used to transfer data to and from a server using various protocols. It is very useful for testing APIs, downloading files and so much more. Curl comes preinstalled on many operating systems, including many Linux distributions and MacOS.
Here is the basic syntax for using Curl:
curl [options] [URL...]
The options
argument is used to specify what kind of request you want to make and to provide any additional information that the request might need.
Here are some examples of Curl commands:
- To send a GET request to a URL:
curl http://example.com
- To send a POST request with data:
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://example.com
- To send a PUT request:
curl -X PUT -d "param1=value1¶m2=value2" http://example.com
- To send a DELETE request:
curl -X DELETE http://example.com
- To include additional headers with your request:
curl -H "Authorization: Bearer ACCESS_TOKEN" http://example.com
- To follow redirects:
curl -L http://example.com
- To save the output to a file:
curl -o filename http://example.com
- To download a file:
curl -O http://example.com/filename
Remember to replace http://example.com
with the URL you are trying to access, and replace any data or headers with the actual data or headers you need to send with your request.