curl: PUT

Testing curl PUT commands.

Start by creating an HTTP PUT server:

and run with python SimpleHTTPPutServer.py

then:

curl -XPUT -H "Content-Type: application/json" http://localhost:8000 -d '{"test": null}'

and now you can mess around creating arbitrary PUT commands.

E.g.

  1. spaces don’t matter between -H and quotes.

-H"Content-Type

is the same as:

-H "Content-Type

2. Double quotes == Single quotes. E.g.

-H'Content is OK

3. argument to -dmust be surrounded in quotes. E.g.

-d 'test=test' is OK.

-d test=test is NOT OK.

E.g. see examples here:

https://gist.github.com/subfuzion/08c5d85437d5d4f00e58

 

curl: tips – silent, using variables in bash

silent

-s=> silent – so no Progress bar

-S=> don’t output errors

https://stackoverflow.com/questions/7373752/how-do-i-get-curl-to-not-show-the-progress-bar

bash variables

Using a variable in a curl call within Bash – remember to double-escape quotes. E.g.

https://stackoverflow.com/questions/40852784/how-can-i-use-a-variable-in-curl-call-within-bash-script

processing curl output

e.g. I wanted to count the lines from a GET for an Elasticsearch nodes. This seemed the obvious:

curl 0:9200/_cat/indices?v&health=yellow | wc -l

but there are a few things wrong here.

1. it outputted everything to the terminal including all the green nodes and then seemed to hang until I hit Enter – not what I was expecting

Solution:

there’s an ampersand character in the URL.

2. also there’s progress output from curl

Solution:

silence with -s

curl -s "0:9200/_cat/indices?v&health=yellow" | wc -l

3. you still get the header from elasticsearch. i.e.

health status index uuid pri rep docs.count docs.deleted store.size pri.store.size