← All activities
Week 8 · Activity
Activity: Your first curl query
Run a few example API calls with curl to practice before working with your own API. Estimated time: 15 minutes.
📋 What to do
- Stage 1: Open a command line. Open Git Bash (Windows) or Terminal (macOS/Linux). If
curl --versiondoes not work yet, finish the Install Git, Git Bash and curl activity first. - Stage 2: Make a GET request. An API is a web address that returns data instead of a web page. Ask this practice API for user number 2:
curl -X GET "https://jsonplaceholder.typicode.com/users/2"
Review the JSON response: it is a record with a name, an email, an address and more. This practice API needs no account and no API key. - Stage 3: Send query parameters. Add
?and aname=valuepair to the address to filter what comes back:curl -X GET "https://jsonplaceholder.typicode.com/users?id=5"
Notice that you got user 5 back, and nobody else. - Stage 4: Add a header. Headers carry extra information, such as the format you want or, for most real APIs, an API key. This practice API ignores the header, but the pattern is the same one you will use later with a key:
curl -X GET "https://jsonplaceholder.typicode.com/users/2" \ -H "Accept: application/json" - Stage 5: Send data with a POST request. This sends JSON to create a new user (the practice API pretends to save it):
curl -X POST "https://jsonplaceholder.typicode.com/users" \ -H "Content-Type: application/json" \ -d '{"name": "Ada Lovelace", "job": "engineer"}'The response echoes your data back with a newid. - Take a screenshot showing the successful output (the JSON response) of at least one of your commands, and paste it into the Canvas text submission box.
📮 Submit
Submit on Canvas (1 pt) — graded on completion; your deadline is on the Canvas assignment.
Note: this page reproduces the activity instructions so you can find them again after class, and it is the version kept current — surveys, slide decks and helper links are updated right here. Submit on Canvas; the due date and your grade live there.