From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../fr/web/api/fetch_api/basic_concepts/index.html | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 files/fr/web/api/fetch_api/basic_concepts/index.html (limited to 'files/fr/web/api/fetch_api/basic_concepts') diff --git a/files/fr/web/api/fetch_api/basic_concepts/index.html b/files/fr/web/api/fetch_api/basic_concepts/index.html new file mode 100644 index 0000000000..9d87d1cc6e --- /dev/null +++ b/files/fr/web/api/fetch_api/basic_concepts/index.html @@ -0,0 +1,66 @@ +--- +title: 'Fetch : concepts de départ' +slug: Web/API/Fetch_API/Basic_concepts +translation_of: Web/API/Fetch_API/Basic_concepts +--- +

{{DefaultAPISidebar("Fetch API")}}{{draft}}

+ +
+

L'API Fetch fournit une interface pour récupérer des ressources (y compris depuis le réseau). Elle paraîtra familière à quiconque aura déjà utilisé {{domxref("XMLHttpRequest")}}, mais elle fournit un jeu de fonctionnalités plus puissantes et plus souples. Cet article explique quelques uns des principes de base de l'API Fetch.

+
+ +
+

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 Mozilla IRC (#mdn room.)

+
+ +

In a nutshell

+ +

At the heart of Fetch are the Interface abstractions of HTTP {{domxref("Request")}}s, {{domxref("Response")}}s, {{domxref("Headers")}}, and {{domxref("Body")}} payloads, along with a {{domxref("GlobalFetch.fetch","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 {{jsxref("Promise")}}-based.

+ +

Guard

+ +

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

+ +

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

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
new object's typecreating constructorguard setting of associated {{domxref("Headers")}} object
{{domxref("Request")}}{{domxref("Request.Request","Request()")}}request
{{domxref("Request.Request","Request()")}} with {{domxref("Request.mode","mode")}} of no-corsrequest-no-cors
{{domxref("Response")}}{{domxref("Response.Response","Response()")}}response
{{domxref("Response.error","error()")}} or {{domxref("Response.redirect","redirect()")}} methodsimmutable
+ +

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

+ + -- cgit v1.2.3-54-g00ecf