Consider a REST API endpoint that returns a JSON object representing a resource. What will be the output when the following Python code simulates a GET request to this resource?
import json def get_resource(): resource = { "id": 101, "type": "book", "attributes": { "title": "Learn REST", "author": "Jane Doe" }, "links": { "self": "/api/books/101" } } return json.dumps(resource) print(get_resource())
Look carefully at how the JSON object is structured with nested dictionaries and keys.
The function returns a JSON string with keys 'id', 'type', 'attributes', and 'links' exactly as defined. Option C matches this structure exactly.
In resource-based design thinking for REST APIs, which HTTP method should be used to update only some fields of an existing resource without replacing the entire resource?
Think about the difference between replacing a resource and modifying parts of it.
PATCH is designed to partially update a resource, while PUT replaces the entire resource. GET retrieves, and DELETE removes the resource.
Which option shows an incorrect RESTful resource URL design for accessing a user's order?
Consider the hierarchy and logical nesting of resources in RESTful URLs.
Option D places 'orders' before 'users', which breaks the logical parent-child relationship. Orders belong to users, so user ID should come first.
Given a REST API returning multiple book resources, which JSON response is correctly formatted to represent a collection?
Look for proper JSON syntax with arrays and objects.
Option B correctly uses a key 'books' with an array of book objects. Option B is valid JSON but lacks a key to identify the collection. Options A and B have syntax errors.
When a new resource is successfully created using a POST request, which HTTP status code should the server return?
Think about the standard code that indicates a new resource was made.
201 Created indicates that the request has succeeded and a new resource has been created as a result. 200 OK is generic success, 204 No Content means success with no body, and 202 Accepted means request accepted but not completed.