Which URL best follows REST API principles by avoiding verbs and focusing on resources?
Think about URLs as nouns representing resources, not actions.
REST APIs should use nouns in URLs to represent resources. Actions like 'create' or 'add' are verbs and should be avoided in URLs. Instead, HTTP methods (POST, GET, PUT, DELETE) define the action.
What is the main reason to avoid verbs in REST API URLs?
Consider how HTTP methods and URLs work together in REST.
In REST, URLs represent resources (nouns), and HTTP methods (GET, POST, PUT, DELETE) specify the action (verb). This separation keeps APIs clean and consistent.
Look at this URL used in a REST API: /deleteOrder/123. What is the main issue with this URL design?
Think about how REST APIs separate actions from resource paths.
REST APIs should avoid verbs in URLs. The action 'delete' should be expressed by the HTTP DELETE method, while the URL should identify the resource, e.g., /orders/123.
Which URL correctly follows RESTful design principles for updating a user with ID 45?
Remember, URLs should represent resources, and HTTP methods specify the action.
The URL should identify the resource (/users/45). The update action is indicated by using the HTTP PUT or PATCH method, not by verbs in the URL.
You want to design a REST API URL to get products filtered by category 'electronics'. Which URL follows REST principles best?
Think about how to represent filtering in REST APIs using query parameters.
Filtering is best done using query parameters. The URL /products?category=electronics represents the products resource filtered by category without using verbs.