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

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:

主站蜘蛛池模板: 青冈县| 昭觉县| 美姑县| 繁峙县| 杭锦旗| 类乌齐县| 得荣县| 星子县| 阿尔山市| 苗栗市| 邻水| 宁津县| 稷山县| 怀集县| 西和县| 汕尾市| 微博| 巩留县| 犍为县| 辛集市| 宜黄县| 温泉县| 抚远县| 织金县| 襄汾县| 金坛市| 延安市| 黄浦区| 萨嘎县| 城口县| 砚山县| 彩票| 镇赉县| 开平市| 嵩明县| 西安市| 仪陇县| 万盛区| 镇远县| 会东县| 肇庆市|