Web Technology Basics

Which of the following is an appropriate web API design that follows the principles of REST?

  1. APut the operation name into the URL, as in /getUser?id=42 or /deleteUser?id=42, and send everything with GET
  2. BRepresent a user resource with a URL such as /users/42 and express operations with HTTP methods, such as GET to retrieve and DELETE to delete
  3. CHave the server remember each client's earlier requests, so that the next request only sends a short command that depends on them
Show answer and explanation

Answer: B. Represent a user resource with a URL such as /users/42 and express operations with HTTP methods, such as GET to retrieve and DELETE to delete

In REST, the things being handled are represented as resources identified by URLs, and operations on them are expressed with HTTP methods such as GET (retrieve), POST (create), PUT or PATCH (update) and DELETE (delete). For example, GET /users/42 retrieves a resource, and when POST /users creates a new user, the server returns 201 Created with the URL of the new resource. Each request is made stateless, containing all the information needed to process it. If an operation such as deletion is done with GET, data may be lost merely because a browser fetches links in advance or a crawler visits.

  • A. Putting operation names into URLs differs from the REST approach. Also, deleting with GET risks unintended execution, for example when links are fetched in advance.
  • B. Correct. Resources are expressed with URLs and operations with HTTP methods.
  • C. In REST each request is independent, and the design is stateless so the server does not rely on earlier requests.
Practice this topic Back to topic

Books on Web Technology Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Web Technology Basics questions

  1. A browser opens https://www.example.com:8443/docs/guide.html?lang=ja#install. Which part of this URL is not included in the request sent to the server and is used only inside the browser after the page loads?
  2. To put the Japanese character "あ" into a URL query, the byte sequence representing it in UTF-8 (E3 81 82) is percent-encoded. Which of the following is the correct result?
  3. A chat app needs to deliver new messages from the server to the browser immediately. Which of the following correctly describes WebSocket?
  4. A merchant's server wants to know immediately when a payment is completed on an online payment service. Which of the following correctly describes the method in which the payment service sends a notification by HTTP POST to a URL the merchant registered in advance (a webhook)?
  5. Which of the following correctly describes the DOM (Document Object Model) used in browsers?