A developer built a small lab inventory API. Reading is GET /api/devices/101, deleting a device is GET /api/devices/101?delete=true, and the service stores each client's last filter so the next call can return the next page. The reviewer wants one change that matches REST principles. Which single revision best brings the lab inventory API in line with REST method and statelessness rules?
Select an answer to reveal the explanation.
Short Explanation
You’re on the right track when GET only reads and removal uses DELETE on the resource. To stay stateless, include the page position with each request instead of relying on a saved client filter; think of bringing your own place marker each time.
Full Explanation
HTTP methods carry meaning: GET is safe, so its requested semantics do not change the resource; DELETE is idempotent, so repeating it has the same intended effect as making it once. Using DELETE for removal and keeping GET read-only makes the requested operation clear and avoids using a safe method for a state-changing action. Statelessness means each request carries the context needed to process it, rather than relying on per-client session state retained between requests. Sending the page position with each request meets that rule. Keeping the filter server-side so paging resumes easily still relies on stored client state, even when deletion uses DELETE and GET remains read-only. Keeping ?delete=true uses GET for a state-changing operation; targeting the same resource URI does not make that method choice safe. Caching the client’s last filter in the API gateway also relies on per-client state, even though removal uses DELETE. The server may still store resource state, and other clients or events may change a resource, so repeated GET requests are not guaranteed to return identical representations. Exam caveat: real APIs sometimes use POST for actions with no natural resource, so judge each case by its method semantics and constraints. Practical check: verify that GET never changes a resource and that every paging request includes the page position it needs.