Amping-Up Windows Command Prompt with cURL and JQ
In this walkthrough post, i'll configure Windows Command Prompt with cURL and JQ.
Introduction
cURL stands for Client URL. It is a command-line tool for getting or sending files using URL syntax. cURL uses libcurl and supports a range of common Internet protocols, currently including HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, LDAP, DAP, DICT, TELNET, FILE, IMAP, POP3, SMTP and RTSP.
jq is a lightweight and flexible command-line JSON processor. It can be used to slice and filter and map and transform structured data. it is available for use on Linux, OS X, FreeBSD, Solaris and Windows OS platforms.
Goals
- cURL Installation
- jq Installation
- Running cURL Commands
- Running jq Commands
cURL Installation
- In the Source Archives section of the Download page on the curl:// website, click on the zip file to download the most recent version of the curl release.
- Extract the zip file and navigate to the bin folder and add this folder location to Path system variable
jq Installation
- jq can be installed on the Windows operating system platforma via Choclatey package manager for Windows or by downloading the executables.
Running cURL Commands
- To test if the tool is configured correctly, open the command prompt and execute the command
curl https://postman-echo.com/get?test=123
- Correct configuration of the tool will return the following response
-
cURL can also be used with a web URL,
curl www.example.com
-
-o flag can be used to store the output in a file
curl -o example.html www.example.com
Running jq Commands
- To pretty print the JSON response append
| jq
to the command. Examplecurl https://postman-echo.com/get?test=123 | jq
{
"args": {
"test": "123"
},
"headers": {
"host": "postman-echo.com",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"cookie": "sails.sid=s%3ADexAdKWXxr2RZM2U-6F9xyUQBvuZyaLo.3%2BnzoTpZ5FCrEtZAcAKIl1eU%2FbNW2BC0iajUmZNLFyU",
"if-none-match": "W/\"22a-Q9lcTyXWV1v2NXWIuNgz34YwP7U\"",
"referer": "https://anantharajuc.github.io/cURL-for-Windows/",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
"x-forwarded-port": "443",
"x-forwarded-proto": "https"
},
"url": "https://postman-echo.com/get?test=123"
}
Resources
- Everything curl - eBook - Web Version, PDF, Mobi, ePub.
- cURL source code on GitHub.
- A playground for jq, (written in Go) with examples and cheatsheet.