C.W.K.
Stream
Lesson 04 of 13 · published

curl Advanced — APIs & Auth

~15 min · curl, post, json, api, auth

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

Talking to APIs from the command line

curl is the standard for testing REST/JSON APIs without writing any code. Every method, every header, every form upload — one tool, one mental model. You'll use this constantly.

Common API patterns

POST JSON, attach an Authorization header, follow PUT/DELETE semantics, upload a file with multipart form. The flags compose cleanly: -X METHOD selects the HTTP verb, -H adds a header, -d attaches a body, -F uploads form/multipart fields.

Code

API request patterns·bash
# Bearer-auth GET with custom Accept
curl -H 'Authorization: Bearer ${TOKEN}' \
     -H 'Accept: application/json' \
     https://api.example.com/users

# POST JSON
curl -X POST \
     -H 'Content-Type: application/json' \
     -d '{"name":"you_username","role":"admin"}' \
     https://api.example.com/users

# POST form-encoded
curl -X POST \
     -d 'username=you_username&password=secret' \
     https://example.com/login

# PUT update
curl -X PUT -H 'Content-Type: application/json' \
     -d '{"role":"superadmin"}' \
     https://api.example.com/users/1

# DELETE
curl -X DELETE -H 'Authorization: Bearer ${TOKEN}' \
     https://api.example.com/users/1

# Multipart file upload
curl -F 'file=@/path/to/document.pdf' \
     https://api.example.com/upload

# Skip TLS verification (TESTING ONLY — never in production)
curl -k https://self-signed.example.com

External links

Exercise

Pick a public API (httpbin.org is great for testing). Run a GET, POST a JSON body to /post, attempt a PUT to /put. Read each response. Save a body to a file (-o), then re-POST it with --data-binary @file. By the end you should be able to talk to any HTTP API from the terminal without copy-paste from documentation.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.