- 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:

- Python編程自學(xué)手冊
- 高手是如何做產(chǎn)品設(shè)計的(全2冊)
- 零基礎(chǔ)搭建量化投資系統(tǒng):以Python為工具
- Mastering Ember.js
- 樂學(xué)Web編程:網(wǎng)站制作不神秘
- Getting Started with PowerShell
- Java性能權(quán)威指南(第2版)
- Python高效開發(fā)實戰(zhàn):Django、Tornado、Flask、Twisted(第3版)
- JavaScript動態(tài)網(wǎng)頁開發(fā)詳解
- Android項目實戰(zhàn):手機安全衛(wèi)士開發(fā)案例解析
- C++語言程序設(shè)計
- 移動增值應(yīng)用開發(fā)技術(shù)導(dǎo)論
- C++ System Programming Cookbook
- 從零開始:C語言快速入門教程
- JavaScript編程精解(原書第2版)