Challenge - 5 Problems
API Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this simple GET request?
Consider this HTTP GET request to a public API that returns JSON data about a user. What will be the output printed by the code?
Rest API
import requests response = requests.get('https://jsonplaceholder.typicode.com/users/1') print(response.json()['username'])
Attempts:
2 left
💡 Hint
Look at the user data returned by the API for user with ID 1.
✗ Incorrect
The API returns a JSON object for user 1, whose username is "Bret". Accessing the 'username' key prints "Bret".
🧠 Conceptual
intermediate1:00remaining
Which HTTP status code indicates a successful GET request?
When you make a GET request to an API and it succeeds, which HTTP status code do you usually get?
Attempts:
2 left
💡 Hint
Think about the code meaning: 200 means OK.
✗ Incorrect
HTTP status code 200 means the request was successful and the server returned the requested data.
❓ Predict Output
advanced2:00remaining
What is the output of this POST request code?
This code sends a POST request to create a new post. What will be printed?
Rest API
import requests url = 'https://jsonplaceholder.typicode.com/posts' data = {'title': 'foo', 'body': 'bar', 'userId': 1} response = requests.post(url, json=data) print(response.json()['id'])
Attempts:
2 left
💡 Hint
The API returns a new post with an id starting at 101.
✗ Incorrect
The fake API returns a new post with id 101 for the created resource.
🔧 Debug
advanced2:00remaining
What error does this code raise?
This code tries to get a user but has a mistake. What error will it raise?
Rest API
import requests response = requests.get('https://jsonplaceholder.typicode.com/users/9999') print(response.json()['username'])
Attempts:
2 left
💡 Hint
User 9999 does not exist, so the JSON response is empty.
✗ Incorrect
The API returns an empty object {} for user 9999. Accessing 'username' key raises KeyError.
🚀 Application
expert2:00remaining
How many items are in the list returned by this API call?
This code fetches all users. How many user objects are in the returned list?
Rest API
import requests response = requests.get('https://jsonplaceholder.typicode.com/users') users = response.json() print(len(users))
Attempts:
2 left
💡 Hint
The API returns 10 users in the list.
✗ Incorrect
The API returns a list of 10 user objects for the /users endpoint.