Curl syntax examples for POST and GET data

Posted by

cURL is a command line tool which is used all over the world to communicate with web applications. The cURL filosopy is based on Unix style programming. It can be used on multiple OS platforms and integrates perfectly in all kind of scripts or other automation purposes. Since I started to work more with Linux and Python I decided to learn more about cURL and the cURL syntax. On Windows I was used to make use of Invoke-Webrequest or Invoke-Restmethod. In my opinion and in my daily work I use cURL for fast testing against webservices and API’s. For more complicated scripts I use other modules. In this post I will show some basic curl commands.

Curl Examples

Currently working on a Ansible AWX project, so my examples are based on commands for managing Ansible AWX.

Curl post json example

POST request you need to specify the -X parameter with POST.
When you post data to a web service its necessary to tell cURL what kind of format you post. This can be done with the -H parameter. The -d parameter stands for data which is formatted with the value you specified in -H.

Curl post json:

Curl Post json data from file:

Curl get example

Save curl output example

In some situations its handy to save the output to a file. This can easily archived with the -o parameter. Complete request with output to a file.

Curl syntax and parameters

Added the help file below, for other parameters.

Leave a Reply

Your email address will not be published.