Skip to content

Instantly share code, notes, and snippets.

@kmwhite
Created February 10, 2021 17:37
Show Gist options
  • Save kmwhite/56fdf20a266ef3449c8bcc6b8213f07f to your computer and use it in GitHub Desktop.
Save kmwhite/56fdf20a266ef3449c8bcc6b8213f07f to your computer and use it in GitHub Desktop.
json curl wrapper
#!/usr/bin/env bash
set -x
CURL_BIN="$(which curl)"
[ -z "$CURL_BIN" ] && echo "cURL must be installed for use!" && exit 255
[ -z "$1" ] && echo "A HTTP Method is Required to call" && exit 1
METHOD="-X $1"
[ -z "$2" ] && echo "A URL is required to use" && exit 2
URL="$2"
if [ -z "$3" ]; then
$CURL_BIN -qi -o - -H "Content-Type: application/json" -H "Accept: application/json" $JC_EXTRA_HEADERS $METHOD $URL
else
DATA="-d @${3}"
$CURL_BIN -qi -o - -H "Content-Type: application/json" -H "Accept: application/json" $JC_EXTRA_HEADERS $METHOD $DATA $URL
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment