Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note that the emphasis is on the URL rather than the HTTP method. The only reason POST must be used in two of the APIs is because GET normally cannot send payload content. The main point is that there are four different APIs (/GetUser, /CreateUser, /UpdateUser, and /DeleteUser) that have to be documented and supported by the client. REST APIs treat the server as a destination where resources are accessed. While the server may indeed be executing procedures, this is obscured from the URL itself, allowing the user to think about the resource as an item rather than an action. REST APIs rely upon the HTTP method (GET, POST, PUT, DELETE, etc.) to determine what should happen to that resource. Hence, through the use of these HTTP methods, a single URL can take on several meanings. This simplifies API design and the need for extensive documentation, as seen below:

  • GET /Users (Retrieves a list of all users from the server.)
  • GET /Users/GeorgeWashington (Retrieves the user with an ID of GeorgeWashington from the server.)
  • POST PUT /Users/GeorgeWashington (Assuming there is a payload with user information, this will create a new user with an ID of GeorgeWashington on the server.)
  • PUT /Users/GeorgeWashington (Assuming there is a payload with updates user information, this will update the user with an ID of GeorgeWashington on the server with only the information provided.)
  • DELETE /Users/GeorgeWashington (Deletes the user with an ID of GeorgeWashington from the server.)

With the RESTful approach, there is typically only one API, /Users, which is much easier to remember and document that four APIs. The HTTP methods are what define the behavior of the API, and since these methods are formally established in the HTTP protocol, they are not subject to redefinition, change, or require republication with each set of RESTful APIs.


Two of the most notable features of RESTful web APIs are:

...