Fetch basic concepts - Web APIs 编辑

Draft

This page is not complete.

The Fetch API provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used XMLHttpRequest, but it provides a more powerful and flexible feature set. This article explains some of the basic concepts of the Fetch API.

Note: This article will be added to over time. If you find a Fetch concept that you feel needs explaining better, let someone know on the MDN discussion forum, or MDN Web Docs room on Matrix.

In a nutshell

At the heart of Fetch are the Interface abstractions of HTTP Requests, Responses, Headers, and Body payloads, along with a global fetch method for initiating asynchronous resource requests. Because the main components of HTTP are abstracted as JavaScript objects, it is easy for other APIs to make use of such functionality.

Service Workers is an example of an API that makes heavy use of Fetch.

Fetch takes the asynchronous nature of such requests one step further. The API is completely Promise-based.

Guard

Guard is a feature of Headers objects, with possible values of immutable, request, request-no-cors, response, or none, depending on where the header is used.

When a new Headers object is created using the Headers() constructor, its guard is set to none (the default). When a Request or Response object is created, it has an associated Headers object whose guard is set as summarized below:

new object's typecreating constructorguard setting of associated Headers object
RequestRequest()request
Request() with mode of no-corsrequest-no-cors
ResponseResponse()response
error() or redirect() methodsimmutable

A header's guard affects the set(), delete(), and append() methods which change the header's contents. A TypeError is thrown if you try to modify a Headers object whose guard is immutable. However, the operation will work if

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:45 次

字数:5323

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文