diff options
author | Jefferson Julio <[email protected]> | 2022-05-14 20:20:37 -0300 |
---|---|---|
committer | Jefferson Julio <[email protected]> | 2022-05-14 20:20:37 -0300 |
commit | 2ff04235bce9bfc7a31ae5b612d87ebbb53f3fa6 (patch) | |
tree | 15e2dc38f0474c6970cb3efa55afbc3e047a5e35 | |
parent | 1b359e05fec31c8362b467c071a796194b52de26 (diff) | |
download | rest-run-2ff04235bce9bfc7a31ae5b612d87ebbb53f3fa6.tar.bz2 rest-run-2ff04235bce9bfc7a31ae5b612d87ebbb53f3fa6.zip |
Specify http method as option parameter.
-rwxr-xr-x | rest-run | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -17,6 +17,7 @@ Positional arguments: You must provide the API URL. An HTTP verb preceding it is accepted if present. Options: + -x|--method HTTP Method -b|--body Request body source, must be one of the following options: default - create a request body using the default editor last - use the last request @@ -121,6 +122,7 @@ while (( "$#" )); do -b|--body) [[ -n "$2" && ${2:0:1} != "-" ]] && rest_body=$2 && shift 2 || opt-fail $1 ;; -r|--response) [[ -n "$2" && ${2:0:1} != "-" ]] && rest_response=$2 && shift 2 || opt-fail $1 ;; -h|--header) [[ -n "$2" && ${2:0:1} != "-" ]] && rest_headers+=("$2") && shift 2 || opt-fail $1 ;; + -x|--method) [[ -n "$2" && ${2:0:1} != "-" ]] && rest_method="$2" && shift 2 || opt-fail $1 ;; -*|--*=) fail "Unkown option $1" ;; *) PARAMS="$PARAMS $1" && shift ;; esac @@ -139,17 +141,18 @@ IFS=' ' read -r -a ARGS <<< "$PARAMS" if [[ ${#ARGS[@]} -gt 1 ]]; then rest_method="${ARGS[0]}" - case "$rest_method" in - POST|post);; - GET|get);; - PUT|put);; - PATCH|patch);; - DELETE|delete);; - *) fail "Invalid HTTP Verb $rest_method" ;; - esac unset 'ARGS[0]' fi +case "$rest_method" in + POST|post);; + GET|get);; + PUT|put);; + PATCH|patch);; + DELETE|delete);; + *) fail "Invalid HTTP Verb $rest_method" ;; +esac + [[ -z "$PARAMS" || "${#PARAMS}" = "1" ]] && fail "Not enough params" rest_url="${ARGS[*]}" |