example.sh 757 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. # [[file:example.org::*Get JSON from an API][Get JSON from an API:1]]
  3. URL='https://reqres.in/api/users'
  4. PAGE='1'
  5. curl -s "${URL}?page=${PAGE}" -H "Content-Type: application/json" \
  6. | jq
  7. # Get JSON from an API:1 ends here
  8. # [[file:example.org::prepare-data][prepare-data]]
  9. USERNAME='morpheus'
  10. JOB='bar'
  11. read -r -d '' DATA <<EOF
  12. {
  13. "name": "${USERNAME}",
  14. "job": "${JOB}"
  15. }
  16. EOF
  17. printf "%s" "${DATA}"
  18. # prepare-data ends here
  19. # [[file:example.org::send-request][send-request]]
  20. DATA='{
  21. "name": "morpheus",
  22. "job": "bar"
  23. }'
  24. URL='https://reqres.in/api/users'
  25. curl \
  26. --request POST \
  27. --silent "${URL}" \
  28. --header "Content-Type: application/json" \
  29. --data "${DATA}" \
  30. | jq -r ".createdAt"
  31. # send-request ends here