Building RESTful Web Services with Spring 5(Second Edition)
上QQ阅读APP看书,第一时间看更新

HTTP methods

Based on HTTP 1.1 specifications, the following are method definitions:

  • GET: This method gets the information mentioned in the URI. The GET method can be used for single or multiple items.
  • POST: This method creates the item mentioned in the URI. Generally, the POST method will be used for item creation and more secured options. As the parameters are hidden in POST, it will be secure compared to the GET method.
  • DELETE: This methods deletes the item in the requested URI.
  • PUT: This method updates the item in the requested URI. According to the HTTP specifications, the server can create the item if the item is not available. However, this will be decided by the developer who designed the application.
  • Advanced HTTP methods: Though we may not use advanced methods all the time, it will be good to know these methods, as they might be useful:
    • HEAD: This method gets meta information about the resource, not the resource itself, as a response. It will be used for caching purposes.
    • TRACE: This method is mostly used for debugging purposes where the contents of an HTTP request will be sent back to the requester.
    • CONNECT: This is used to open a tunnel and can be used for proxy purposes.
    • OPTIONS: This method is used to describe communication options for the target resource.

The following are HTTP method recommendations for our CRUD operations:

In the rest of the chapter, we will show how to build CRUD operations.