First API Script ✅
Built a Python script that talks to JSONPlaceholder: lists every post, creates a new one, and handles failures gracefully.
What it does
GET all posts → prints the count using len()
POST a new post with my name as title → prints status code + new id
try/except with friendly messages for timeouts, connection errors, HTTP errors
Bonus: f-strings everywhere + a list comprehension for the first 3 titles
Real output
Total posts on JSONPlaceholder: 100
First three titles: ['sunt aut facere repellat...', 'qui est esse', 'ea molestias quasi...']
POST status code: 201
New post id: 101
New post title echoed: 'Alex'
Real failure mode (bonus story)
The API went down for a few hours yesterday. My script caught it cleanly:
Request took too long — check your connection and try again.
That's the whole point of try/except — your script doesn't crash when reality misbehaves. Better proof than any mocked timeout.
Takeaway
201 Created returns the new resource (so you get the id back). len() on a JSON array gives you the count without parsing. f-strings beat .format() for readability. Specific exception classes beat a bare except: because they tell you what went wrong.