{
  "type": "module",
  "source": "doc/api/api-globalinstallation.md",
  "modules": [
    {
      "textRaw": "Global Installation",
      "name": "global_installation",
      "introduced_in": "v7.11.0",
      "type": "module",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>undici ships its own implementations of several WHATWG web APIs. The <code>install()</code>\nfunction assigns those implementations onto <code>globalThis</code>, so they can be used\nwithout importing them from <code>'undici'</code> first. This is useful for polyfilling\nenvironments, guaranteeing consistent behavior across Node.js versions, and\nsatisfying third-party libraries that expect the relevant classes to be global.</p>\n<pre><code class=\"language-mjs\">import { install } from 'undici'\n\ninstall()\n\n// `fetch`, `Headers`, `Response`, `Request`, etc. now resolve to undici's\n// implementations.\nconst response = await fetch('https://example.com')\n</code></pre>\n<pre><code class=\"language-cjs\">const { install } = require('undici')\n\ninstall()\n</code></pre>",
      "methods": [
        {
          "textRaw": "`install()`",
          "name": "install",
          "type": "method",
          "meta": {
            "added": [
              "v7.11.0"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [],
              "return": {
                "textRaw": "Returns: {undefined}",
                "name": "return",
                "type": "undefined"
              }
            }
          ],
          "desc": "<p>Overwrites the following properties of <code>globalThis</code> with undici's\nimplementations:</p>\n<ul>\n<li><code>globalThis.fetch</code></li>\n<li><code>globalThis.Headers</code></li>\n<li><code>globalThis.Response</code></li>\n<li><code>globalThis.Request</code></li>\n<li><code>globalThis.FormData</code></li>\n<li><code>globalThis.WebSocket</code></li>\n<li><code>globalThis.CloseEvent</code></li>\n<li><code>globalThis.ErrorEvent</code></li>\n<li><code>globalThis.MessageEvent</code></li>\n<li><code>globalThis.EventSource</code></li>\n</ul>\n<p>Each installed value is the same object exported by <code>'undici'</code> under the\nmatching name, so the global identifiers form a single, self-consistent set.\nThe assignment is unconditional: any pre-existing global of the same name,\nincluding the Node.js built-in, is replaced. The change persists for the\nlifetime of the process. Calling <code>install()</code> more than once is safe and simply\nre-assigns the same values.</p>\n<p>Documentation for each installed class lives on its own page: see\n<a href=\"Fetch.html\"><code>fetch</code></a>, <a href=\"WebSocket.html#class-websocket\"><code>WebSocket</code></a>, and <a href=\"EventSource.html#class-eventsource\"><code>EventSource</code></a>.</p>\n<pre><code class=\"language-mjs\">import { install } from 'undici'\n\ninstall()\n\nconst headers = new Headers([['content-type', 'application/json']])\nconst request = new Request('https://example.com')\nconst formData = new FormData()\nconst ws = new WebSocket('wss://example.com')\nconst eventSource = new EventSource('https://example.com/events')\n</code></pre>",
          "modules": [
            {
              "textRaw": "Pairing `fetch` and `FormData`",
              "name": "pairing_`fetch`_and_`formdata`",
              "type": "module",
              "desc": "<p>When a request body is a <code>FormData</code> instance, the <code>fetch</code> and <code>FormData</code>\nimplementations must come from the same source. After <code>install()</code>, both globals\nresolve to undici, so they always match:</p>\n<pre><code class=\"language-mjs\">import { install } from 'undici'\n\ninstall()\n\nconst body = new FormData()\nawait fetch('https://example.com', { method: 'POST', body })\n</code></pre>\n<p>If global installation is not desired, import the matching pair directly from\n<code>'undici'</code> instead:</p>\n<pre><code class=\"language-mjs\">import { fetch, FormData } from 'undici'\n\nconst body = new FormData()\nawait fetch('https://example.com', { method: 'POST', body })\n</code></pre>\n<p>Mixing a global <code>FormData</code> with <code>undici.fetch()</code>, or <code>undici.FormData</code> with the\nbuilt-in global <code>fetch()</code>, can produce surprising multipart behavior across\nNode.js and undici versions. Keep the two paired.</p>",
              "displayName": "Pairing `fetch` and `FormData`"
            },
            {
              "textRaw": "Conditional installation",
              "name": "conditional_installation",
              "type": "module",
              "desc": "<p><code>install()</code> can be guarded so undici's <code>fetch</code> is only installed when no global\n<code>fetch</code> already exists:</p>\n<pre><code class=\"language-mjs\">import { install } from 'undici'\n\nif (typeof globalThis.fetch === 'undefined') {\n  install()\n}\n\nconst response = await fetch('https://example.com')\n</code></pre>",
              "displayName": "Conditional installation"
            }
          ]
        }
      ]
    }
  ]
}