AI Courses

First contact: curl

Written by

in

First contact: curl | Master AI Automation in 4 hours Master AI Automation in 4 hours Course About Ayush Modules Sample chapter Toolbox The Microcap Minute Classroom / Module 04: APIs: How Software Talks / Chapter 4 First contact: curl Watch first, then read. Same lesson, your pace. What you will learn – What curl is – Your first real API call, free, no key needed – Reading a raw JSON response like a menu curl: the waiter’s phone curl (“see URL”) is a terminal command that says “fetch this URL”, it makes web requests from your keyboard. It ships on Mac/Linux; Windows Terminal includes it too. It’s the fastest way to feel what an API call is: one line, request goes, JSON comes back. A free API, no key We need an API that doesn’t demand signup for first contact. Enter a public favourite: curl “https://api.github.com/zen” GitHub’s zen endpoint returns one line of programmer wisdom, no key required. Run it three times; different wisdom each time. You just made three API calls. That’s it. That was the scary thing. Now something with structure: curl “https://api.github.com/users/torvalds” A wall of JSON arrives (Chapter 2 pays off): “login”: “torvalds” , “public_repos”: 8 , “followers”: … . Read it as a menu: label on left, value on right, some values nested boxes. Add -i to see the envelope too: curl -i “https://api.github.com/users/torvalds” HTTP headers appear above the JSON, including status: 200 OK (the kitchen saying “enjoy”) and rate-limit info (how many orders you have left this hour). The shape of every future call Notice what you didn’t need: no app, no browser, no clicks. And notice the pattern you’ll reuse forever: curl -X POST # method when ordering (not just looking) -H “Authorization: Bearer $KEY” # membership card header -H “Content-Type: application/json” # “my order is JSON” -d ‘{“order”: “contents”}’ # the order itself That template, URL, method, headers, data, is 95% of all API calls ever, including AI calls in the next chapter. Today you did the GET version (just looking); Chapter 5 does POST (placing an order). Try it yourself Run both GitHub calls above. Then explore freely: swap torvalds for your own GitHub username (or anyone’s), fetch https://api.github.com/repos/openai/openai-python , and try https://api.github.com/search/repositories?q=minecraft (note how parameters ride in the URL after ? ). Count the status codes you collect. Save your favourite zen quote into learn/zen.txt with curl -s >> learn/zen.txt . Key takeaways – curl makes API requests from the terminal: instant feedback, zero setup. – GET = looking at menus; the response is JSON plus a 200-style status. – Every serious call adds method (-X), headers (-H) and data (-d). – Public endpoints like GitHub’s let you practice free and keyless, use them to experiment fearlessly. Download the exercise sheet (PDF) Module workbook (PDF) โ† Prev: Keys, secrets and .env files Next: Talking to an AI with an API โ†’ Classroom / Module 04: APIs: How Software Talks / Chapter 4 First contact: curl What you will learn – What curl is – Your first real API call, free, no key needed – Reading a raw JSON response like a menu curl: the waiter’s phone curl (“see URL”) is a terminal command that says “fetch this URL”, it makes web requests from your keyboard. It ships on Mac/Linux; Windows Terminal includes it too. It’s the fastest way to feel what an API call is: one line, request goes, JSON comes back. A free API, no key We need an API that doesn’t demand signup for first contact. Enter a public favourite: curl “https://api.github.com/zen” GitHub’s zen endpoint returns one line of programmer wisdom, no key required. Run it three times; different wisdom each time. You just made three API calls. That’s it. That was the scary thing. Now something with structure: curl “https://api.github.com/users/torvalds” A wall of JSON arrives (Chapter 2 pays off): “login”: “torvalds” , “public_repos”: 8 , “followers”: … . Read it as a menu: label on left, value on

๐Ÿ“„ Download PDF

๐Ÿ“„ Download PDF