
Here's a preview from my zine, HTTP: Learn your browser's language!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

read the transcript!
Lots of services (Twitter! Twilio! Google!) let you use them by sending them HTTP requests. If an HTTP API doesn’t come with a client library, don’t be scared! You can just make the HTTP requests yourself. Here’s what you need to remember:
Set the right Content—Type
header
Often you’ll be sending a POST request with a body, and that means you need a Content—Type
header that matches the body.
The 2 main options are:
- application/json
(JSON!)
- application/x-www-form-urlencoded
(same as what an HTML form does)
If you don’t set the Content—Type
, your request won’t work.
Smiling stick figure with short curly hair: a common error is to try to send POST data as one content type (like JSON) when it’s actually another (like application/x-www-form-urlencoded)
Identify yourself
Most HTTP APIs require a secret API key so they know who you are. Here’s how that looks for the Twilio API:
curl
https://api.twilio.com/2010-04-01/Accounts/ACCOUNT_ID/Messages.json
-H "Content-Type: application/json"
-u CCOUNT_ID:AUTH_TOKEN
-d '{
"from": "+15141234567",
"to": "+15141234567",
"body": "a text message"
}'
(this sends a POST request)
u ACCOUNT_ID:AUTHO_TOKEN
sends the username/password in the Authorization
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!