Using curl from the shell/command prompt (ouch) is a great way to test API’s, retrieve files from FTP servers etc etc. Maybe your building an application that consumes an API or maybe your using scripts to perform remote functions. Knowing how to use and test things at this level can often provide that piece of insight that you need when debugging, planning or building solutions.
Prerequisite: have the curl binary installed!
HTTP VERB’s – Use -X and take your pick from the CRUD: curl -X PUT hostname:port/some/uri
Basic Authentication: curl -u username:password hostname:port/some/uri
Query String Params: curl -d “filter=curl_rules” hostname:port/some/uri (you can more -d switches if you need to add more QS params)
Save a webpage: curl -o index.html http://www.google.com
Save a file from an FTP server: curl ftp://ftp.server.com/file.txt
Post a file to a server: curl –data @file.txt hostname:port/some/uri
Define the content Type: curl -H “Content-Type:text/json” –data @file.txt hostname:port/some/uri