Posting JSON data using curl

I've been developing and testing some REST servers recently and while I could use something like XHR Poster, Chrome Poster or Postman I like the ability to run things from the command line partially for simplicity but also so I can later incorporate these things into automation or test tools.

It seems I am always having to re-read the curl man pages and figure this so maybe if I write it down I will remember next time.

The curl command I've been using for posting is pretty straightforward, loading the config from an external file.

curl --config TestPost.txt  


The format of this file basically just a collection of the option flags that you would normally put on the command line.

The primary difference is how you set the url in the file.
Otherwise the format is simple, one line per command line option.

# TestPost.txt
url = "http://localvm:130/api/appointment/CA37341796BF3E3"  
-i 
-X POST
--header "Content-Type: application/json"
-d {"id":"CA37341796BF3E3","name":"TestAppointment","startTime":"2015-05-05T09:15:00.000-0500","durationMinutes":15}

In this case to send the JSON payload two things are needed.
* setting the Content-Type in the header
* sending the JSON as one long line after the -d option Note: that you could also load this data from a second file using the @ notation