Testing with curl

View saved

GET a resource

Print response headers with -i while learning.

curl -i https://httpbin.org/get

POST JSON

Send a body with -d and set Content-Type.

curl -i https://httpbin.org/post \
  -H "Content-Type: application/json" \
  -d '{"title":"Practical APIs"}'

Add auth headers

Pass Bearer tokens or API keys the same way your app will.

curl -i https://api.example.com/v1/books \
  -H "Authorization: Bearer TOKEN"

Helpful flags

  • -X PATCH to set the method
  • -o file to save the body
  • -v for a verbose trace
  • --fail to exit non-zero on HTTP errors

Comments

One comment per signed-in account. Comments are saved with this page’s URL.