0
0
Rest APIprogramming~20 mins

GET for reading resources in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GET Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this GET request example?

Consider this simple REST API GET request example using curl:

curl -X GET https://api.example.com/users/123

The server responds with JSON data about the user. What is the expected output if the user exists?

Rest API
{"id":123,"name":"Alice","email":"alice@example.com"}
A{"error":"User not found"}
B404 Not Found
C{"id":123,"name":"Alice","email":"alice@example.com"}
D500 Internal Server Error
Attempts:
2 left
💡 Hint

GET requests for existing resources usually return status 200 and the resource data.

🧠 Conceptual
intermediate
1:30remaining
Which HTTP status code indicates a successful GET request with no content?

When a GET request is successful but the server has no data to return, which HTTP status code is appropriate?

A204 No Content
B200 OK
C404 Not Found
D500 Internal Server Error
Attempts:
2 left
💡 Hint

Think about a success status that means 'no data' instead of 'data returned'.

🔧 Debug
advanced
2:30remaining
Why does this GET request code cause an error?

Look at this Python code snippet using requests library to GET a resource:

import requests
response = requests.get('https://api.example.com/items')
print(response.json()['data'])

The server returns JSON: {"items": [1,2,3]}. What error occurs and why?

ATypeError because response.json() returns a string, not a dict
BNo error, prints [1,2,3]
CConnectionError because the URL is invalid
DKeyError because 'data' key does not exist in the JSON response
Attempts:
2 left
💡 Hint

Check the keys in the JSON response and what the code tries to access.

📝 Syntax
advanced
2:00remaining
Which option correctly forms a GET request URL with query parameters?

You want to GET a list of products filtered by category 'books' and sorted by price ascending. Which URL is correct?

Ahttps://api.example.com/products?category=books&sort=price_asc
Bhttps://api.example.com/products/category=books&sort=price_asc
Chttps://api.example.com/products?category=books;sort=price_asc
Dhttps://api.example.com/products?category=books&sort=price-asc
Attempts:
2 left
💡 Hint

Query parameters start after '?' and are separated by '&'.

🚀 Application
expert
2:30remaining
What is the number of items returned by this GET request code?

Given this JavaScript fetch code:

const response = await fetch('https://api.example.com/tasks');
const data = await response.json();
console.log(data.tasks.length);

The server responds with JSON:

{"tasks": [{"id":1},{"id":2},{"id":3},{"id":4}]}

What is the output of the console.log statement?

Aundefined
B4
C3
DTypeError
Attempts:
2 left
💡 Hint

Count the number of objects inside the 'tasks' array in the JSON response.