Which of the following is the best practice for naming a REST API endpoint that returns a list of users?
Think about how REST APIs usually represent collections.
REST APIs typically use plural nouns for resource collections. So, /users is the standard way to represent a list of user resources.
Given a REST API endpoint /users/123 that returns the user with ID 123, what is the expected resource name in the URL?
Remember that the collection is plural, and the ID identifies a single resource inside it.
The resource name remains plural for the collection, and the ID specifies the singular resource. So /users/123 is correct.
Which endpoint should be used to create a new book resource in a REST API?
Creating a new resource usually uses POST on the collection endpoint.
POST requests to the plural resource endpoint /books are the standard way to create new resources in REST APIs.
Why is it generally discouraged to use singular resource names like /user to represent a collection in REST APIs?
Think about clarity and expectations for API users.
Using singular names for collections can confuse clients about whether the endpoint returns a single resource or a list, reducing API clarity.
A REST API endpoint /products returns a JSON array of product objects. If the endpoint returns the following JSON:
[{"id":1,"name":"Pen"},{"id":2,"name":"Notebook"},{"id":3,"name":"Eraser"}]How many product items does this endpoint return?
Count the objects inside the JSON array.
The JSON array contains three objects, so the endpoint returns 3 product items.