티스토리 뷰

공부

[curl] PUT, GET (value & file)

승가비 2022. 7. 9. 20:03
728x90
#!/bin/bash

for ARG in "$@"
do
  K=$(echo "${ARG}" | cut -f1 -d=)
  V=$(echo "${ARG}" | cut -f2 -d=)

  case "${K}" in
    ENV) ENV=${V} ;;
    VERSION) VERSION=${V} ;;
    FILE) FILE=${V} ;;
    VALUE) VALUE=${V} ;;
  esac
done

case "${ENV}" in
  stage) path=https://satage/asdf ;;
  production) path=https://production/asdf ;;
esac

if [ -z "${VERSION}" ]; then
  VERSION=v1
fi
path="${path}/${VERSION}"

echo "======================================================="

HEADER="Content-Type: application/json"
if [ ! -z "${FILE}" ]; then
  curl \
  -H "${HEADER}" \
  -X PUT "${path}" \
  -d @"${FILE}"
elif [ ! -z "${VALUE}" ]; then
  curl \
  -H "${HEADER}" \
  -X PUT "${path}" \
  -d "${VALUE}"
else
  curl \
  -H "${HEADER}" \
  -X GET "${path}"
fi

https://stackoverflow.com/questions/13782198/how-to-do-a-put-request-with-curl

 

How to do a PUT request with cURL?

How do I test a RESTful PUT (or DELETE) method using cURL?

stackoverflow.com

https://stackoverflow.com/questions/34847981/curl-with-multiline-of-json

 

Curl with multiline of JSON

Consider the curl command below, is it possible to allow newline in JSON (without the minify) and execute directly in bash (Mac/Ubuntu) curl -0 -v -X POST http://www.example.com/api/users \ -H "Ex...

stackoverflow.com

 

728x90

'공부' 카테고리의 다른 글

[kotlin] list to map  (0) 2022.07.09
[MySQL] user  (0) 2022.07.09
[kotlin] forEach break(return@forEach) & continue(return@run)  (0) 2022.07.09
[kotlin] testcase suspend fun (+ assertThrows)  (0) 2022.07.09
[linux] pushd, popd  (0) 2022.07.09
댓글