- Building RESTful Web Services with PHP 7
- Haafiz Waheed ud din Ahmad
- 331字
- 2021-07-03 00:02:18
Idempotent and non-idempotent methods
There are methods which achieve the same results no matter how many time we repeat the same operations. We consider GET, PUT, PATCH, and DELETE as idempotent methods, as no matter how many times we repeat these method calls, it will always result in the same thing. For example, if you are using GET example.com/books , it will always return the same list of books, no matter how many times you call this URL with the GET method. However, if user put something else in database then it can have different result in listing but to declare some method idempotent or not, we are not considering change in result because of external factors instead of that method call itself. In the same way, if you use PUT or PATCH, let's say PATCH example.com/books/2?author=Ali, it will always result in the same response no matter how many times you call this method with the same parameters.
The same is the case with DELETE. It doesn't matter how many times you call DELETE on the same resource, it will only be deleted once. However, for DELETE, it can vary based on the implementation as well. It is something that depends on how you as a programmer want to implement. You probably want to DELETE and give a successful response the first time and on subsequent calls. You can simply give 404 because the resource no longer exists.
POST is non-idempotent because it creates a new resource on the server and the response has at least one unique attribute (mostly that is the ID of the resource), even if all the other attributes are same in the case of the same request parameters.
Until now, we have understood RESTful web services conventions, URL patterns, HTTP methods, and the nature of HTTP methods. However, it was mostly about requests. The URL and HTTP method are both request-related points. We haven't yet looked at responses, so now let's take a look into that.
- TypeScript入門與實戰(zhàn)
- Kibana Essentials
- MATLAB圖像處理超級學(xué)習(xí)手冊
- Java開發(fā)入行真功夫
- Podman實戰(zhàn)
- PLC編程及應(yīng)用實戰(zhàn)
- Web程序設(shè)計(第二版)
- Swift語言實戰(zhàn)精講
- Learning Raspbian
- Visual Basic程序設(shè)計上機實驗教程
- Natural Language Processing with Java and LingPipe Cookbook
- Kotlin極簡教程
- TypeScript 2.x By Example
- Python計算機視覺與深度學(xué)習(xí)實戰(zhàn)
- Java服務(wù)端研發(fā)知識圖譜