Fetch API - Web APIs | MDN

The Fetch API provides an interface for fetching resources (including across the network). It is a more powerful and flexible replacement for XMLHttpRequest.

En bref

Ajouté le

18 mars 2026

Matière et domaine

coding · apis-integration

Niveaux scolaires

9e année (3e)–12e année (Terminale)

Type de page

Article

Introduction

Overview of the Fetch API

  • Purpose: Provides a modern, powerful, and flexible interface for fetching network resources, serving as a replacement for XMLHttpRequest.
  • Core Mechanism: Uses Request and Response objects, incorporating concepts like CORS and HTTP Origin header semantics.
  • Primary Method: The fetch() method is a global function available in both Window and Worker contexts.
  • Request Handling:
    • Takes a mandatory path argument and an optional init options object.
    • Returns a Promise that resolves to a Response object as soon as headers are received (even if the HTTP status indicates an error).
  • Deferred Fetching: The fetchLater() API allows for requests to be sent after a delay or upon page navigation/closure.
  • Key Interfaces:
    • Request and Response: Represent the network request and server response.
    • Headers: Allows querying and manipulation of request/response headers.
    • fetchLater() / DeferredRequestInit: Used for managing deferred network requests.
  • Usage: While Request() and Response() constructors exist, they are typically generated automatically by API actions like fetch() or service worker events.

Avis de la communauté

Pas encore d’avis publiés. Soyez le premier à partager votre expérience.