scripts/curl-helper.sh

28 lines
579 B
Bash
Raw Permalink Normal View History

2024-07-11 20:09:02 +05:30
#!/usr/bin/env bash
method=$(gum choose GET POST PUT PATCH DELETE)
api_url=$(gum input --placeholder="API URL")
header_json="Content-Type: application/json"
case $method in
"POST" | "PUT" | "PATCH")
body=$(gum input --placeholder="Body(JSON)")
query="curl -H \"$header_json\" -d '{ $body }' -X $method $api_url"
;;
"GET" | "DELETE")
query="curl -X $method $api_url"
;;
*)
echo "Invalid method"
exit 1
;;
esac
echo $query
if gum confirm "Do you want to execute the query"; then
eval $query
else
echo "query execution cancelled"
fi