commit 340a4fd8307c744cd34f59ecdcd60e3e256b6ea2
parent 01f29225519b391f7ee15ffd0559f0d830f9bb21
Author: Wim Dupont <wim@wimdupont.com>
Date: Sun, 19 Mar 2023 11:33:40 +0100
alter script body
Diffstat:
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/src/test/resources/play.sh b/src/test/resources/play.sh
@@ -14,6 +14,8 @@ done
shift $((OPTIND-1))
id=$1
+body_name=
+body_number=
get_id () {
if [ -z "${id}" ]; then
@@ -23,18 +25,28 @@ get_id () {
}
get_url () {
- base_url+="$1"
+ base_url="${base_url}$1"
if [ "${with_error}" -eq 1 ]; then
base_url="${base_url}?errors=true"
fi
echo "${base_url}"
}
+get_body_name () {
+ echo "Request name? (Default= $1)"
+ read -r body_name
+}
+
+get_body_number () {
+ echo "Request number? (Default= $1)"
+ read -r body_number
+}
+
request=
while [[ "${method}" != @(q|quit|e|exit) ]]
do
- echo "Request method? (GET/POST/PUT/DELETE) - q, quit, e, or exit to quit."
+ echo "Request method? (GET/POST/PUT/DELETE) - 'q' or 'quit' to exit script."
read -r method
case ${method^^} in
@@ -49,12 +61,20 @@ do
;;
POST)
- request=$(curl -X POST -sw '%{http_code}' $(get_url) -H 'Content-Type: application/json' -d '{"name":"Created John","number":120}' | jq)
+ get_body_name "Created John"
+ get_body_number 120
+ request=$(curl -X POST -sw '%{http_code}' $(get_url) -H 'Content-Type: application/json' -d "{\"name\":\"${body_name}\",\"number\":\"${body_number}\"}" | jq)
;;
PUT)
get_id
- request=$(curl -X PUT -sw '%{http_code}' $(get_url "/${id}") -H 'Content-Type: application/json' -d '{"name":"Updated John","number":166}' | jq)
+ get_body_name "Updated John"
+ get_body_number 166
+ request=$(curl -X PUT -sw '%{http_code}' $(get_url "/${id}") -H 'Content-Type: application/json' -d "{\"name\":\"${body_name}\",\"number\":\"${body_number}\"}"| jq)
+ ;;
+
+ Q|QUIT)
+ exit 0
;;
DELETE)
@@ -78,4 +98,6 @@ do
echo "${retrieved_id}" | xclip
id=
+ body_name=
+ body_number=
done