官术网_书友最值得收藏!

  • Mastering ASP.NET Web API
  • Mithun Pattankar Malendra Hurbuns
  • 238字
  • 2021-07-02 20:52:24

HTTP POST example

Our HTTP method is POST, and https://api.github.com/gists is our resource. We have a header value in the request as well. User-Agent is the header key, with a value of Awesome-Octocat-App. This is what the documentation has specified.

You can take note of the request body in the following screenshot:

This is our request for a POST method.

Our response from this request is depicted here. The server has responded with 201, which means that our request was valid, and the server has carried out the operation successfully:

The server also sends back a resource to us. A new resource has been born and we can fetch data from this.

POST is not idempotent. Idempotent in the REST world implies that as a client when I call an endpoint more than once, I expect to receive the same behavior or I expect to get back the same data. Consider the example where you have to create a contact with a unique email address. The first time you call POST with this email address and other contact details, the server will respond with 201, which means that contact has been created and a unique resource has been published, where you can fetch that data.

If you call a POST method with the same email address, what will happen? The server should return a conflict, 409. The email exists in the data store. So POST is not idempotent:

主站蜘蛛池模板: 乌审旗| 连平县| 阳原县| 永定县| 沭阳县| 德保县| 河曲县| 安仁县| 基隆市| 齐齐哈尔市| 美姑县| 乐都县| 湖口县| 长宁县| 永清县| 普安县| 千阳县| 同德县| 剑川县| 苍梧县| 新宁县| 神农架林区| 贺州市| 星子县| 漳平市| 茌平县| 临潭县| 房山区| 霍林郭勒市| 洪泽县| 大理市| 临澧县| 新绛县| 马龙县| 锡林浩特市| 本溪市| 凯里市| 长泰县| 遵化市| 聂荣县| 绥芬河市|