HTTP Methods 的绝佳描述(来自“Web Scraping with Python”第88页)

一、引言

这是我在看“Web Scraping with Python”书第88页的时候,由衷的被作者的智慧总结震撼并产生了共鸣,因此衍生了想要转载在博客上分享给大家的想法。

全文是英文,而且我不打算翻译,因为行文比较易懂,读的懂的人,应该会更加有感慨一些。

这段话是在作者为了介绍爬虫技术中的 API 内容附带简要介绍的,这是背景。

以下是正文。

二、Methods

There are four ways to request information from a web sever via HTTP:

  1. GET
  2. POST
  3. PUT
  4. DELETE

GET is what you use when you visit a website through the address bar in your browser. GET is the method you are using when you make a call to http://freegeoip.net/json/50.78.253.58. You can think of GET as saying, “Hey, web server, please get me this information.”

POST is what you use when you fill out a form, or submit information, presumably to a backend script on the server. Every time you log into a website, you are making a POST request with your username and (hopefully) encrpted password. If you are making a POST request with an API, you are saying, “Please store this information in your database.”

PUT is less commonly used when interacting with websites, but is used from time to time in APIs. A put request is used to update an object or information. An API might require a POST request to create a new user, for example, but it might need a PUT request if you want to update that user’s email address.

DELETE is straightforward; it is used to delete an object. For instance, if I send a DELETE request to http://myapi.com/user/23, it will delete the user with the ID 23. DELETE methods are not often encountered in public APIs, which are primarily created to disseminate information rather than allow random users to remove that information from their databases. However, like the PUT method, it’s good one to known about.

Although a handful of other HTTP methods are defined under the specifications for HTTP, these four constitute the entirety of what is used in just about any API you will ever encounter.

三、总结

其实一直以来,对于 HTTP 方法的 GET 和 POST 的含义理解都只是片面(可能与我并未从事相关工作有关)。

其中作者的 You can think of GET as saying, “Hey, web server, please get me this information.” 以及 If you are making a POST request with an API, you are saying, “Please store this information in your database” 这两句话简直醍醐灌顶。

“Web Scraping with Python”是一本好书,而且作者还是一个大美女呢!!!
这里写图片描述

可惜这本书没有在国内上市,不然定要买一本在家珍藏。

这本书还要继续读下去 : )

To be Stronger !

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值