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?
{"id":123,"name":"Alice","email":"alice@example.com"}GET requests for existing resources usually return status 200 and the resource data.
A successful GET request returns status 200 and the requested resource in JSON format.
When a GET request is successful but the server has no data to return, which HTTP status code is appropriate?
Think about a success status that means 'no data' instead of 'data returned'.
204 No Content means the request was successful but there is no content to send back.
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?
Check the keys in the JSON response and what the code tries to access.
The JSON response has key 'items', but code tries to access 'data', causing KeyError.
You want to GET a list of products filtered by category 'books' and sorted by price ascending. Which URL is correct?
Query parameters start after '?' and are separated by '&'.
Option A correctly uses '?' to start query and '&' to separate parameters.
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?
Count the number of objects inside the 'tasks' array in the JSON response.
The 'tasks' array has 4 objects, so length is 4.