curl, jq and slightly dynamic input to a service

I keep forgetting the syntax for these two things, so there’s a chance writing it here will help me remember.

Possibly of use/relevance for: elasticsearch or Debezium….

curl -si -X POST -H 'Accept:application/json' \
     -H 'Content-Type:application/json' \
     http://something:port/somewhere --data @<( cat <<EOF
    "java.script": stuff,
    "": "${ENV_VAR_CAN_BE_USED}"

So ‘cat’ reads till EOF, and outputs on a file descriptor, that the shell passes to curl…

The above ‘@<(‘ can be also used with jq – for example with ElasticSearch to reduce the replica requirements for a testing environment :

curl -si -X PUT -H 'Content-Type:application/json' \ \
    -d @<( 
        jq -c ".settings.index={number_of_shards:1,number_of_replicas:0}" ./existing/file/mapping.json

Leave a comment

Your email address will not be published.