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

Cross-Origin Resource Sharing (CORS)

The most important application of this OPTIONS method is Cross-Origin Resource Sharing (CORS). Initially, browser security prevented the client from making cross-origin requests. It means a site loaded with the www.foo.com URL can only make API calls to that host. If the client code needs to request files or data from www.bar.com, then the second server, bar.com, should have a mechanism to recognize foo.com to get its resources.

The following is the diagram depicting the CORS process:

Let's examine the steps followed in the preceding CORS diagram:

  1. foo.com requests the OPTIONS method on bar.com
  2. bar.com sends a header like Access-Control-Allow-Origin: http://foo.com in response to the client
  3. Next, foo.com can access the resources on bar.com without any restrictions that call any REST method

If bar.com feels like supplying resources to any host after one initial request, it can set the access control to *.

In the next section, we see why the REST API plays such a major role in the next generation of web services. SPAs made it possible to leverage APIs for all purposes, including the UI, clients, and so on.

主站蜘蛛池模板: 恩平市| 峡江县| 永新县| 荔波县| 肥西县| 修文县| 天镇县| 晋宁县| 如皋市| 齐河县| 平陆县| 蓬莱市| 大关县| 富蕴县| 赤峰市| 绥棱县| 烟台市| 松滋市| 漯河市| 汶上县| 嵊泗县| 玉山县| 兰西县| 静乐县| 临湘市| 桃江县| 方城县| 安新县| 沁源县| 博湖县| 贵阳市| 马鞍山市| 瓦房店市| 阳曲县| 盐边县| 东兴市| 大关县| 甘南县| 静安区| 博客| 赤水市|