{
  "type": "module",
  "source": "doc/api/api-globalinstallation.md",
  "modules": [
    {
      "textRaw": "Global Installation",
      "name": "global_installation",
      "type": "module",
      "desc": "<p>Undici provides an <code>install()</code> function to add fetch-related and other web API classes to <code>globalThis</code>, making them available globally without requiring imports.</p>",
      "methods": [
        {
          "textRaw": "`install()`",
          "name": "install",
          "type": "method",
          "signatures": [
            {
              "params": []
            }
          ],
          "desc": "<p>Install undici's global web APIs on <code>globalThis</code>.</p>\n<p><strong>Example:</strong></p>\n<pre><code class=\"language-js\">import { install } from 'undici'\n\n// Install undici's global web APIs\ninstall()\n\n// Now you can use fetch classes globally without importing\nconst response = await fetch('https://api.example.com/data')\nconst data = await response.json()\n\n// All classes are available globally:\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": "Installed Classes",
          "name": "installed_classes",
          "type": "module",
          "desc": "<p>The <code>install()</code> function adds the following classes to <code>globalThis</code>:</p>\n<table>\n<thead>\n<tr>\n<th>Class</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>fetch</code></td>\n<td>The fetch function for making HTTP requests</td>\n</tr>\n<tr>\n<td><code>Headers</code></td>\n<td>HTTP headers management</td>\n</tr>\n<tr>\n<td><code>Response</code></td>\n<td>HTTP response representation</td>\n</tr>\n<tr>\n<td><code>Request</code></td>\n<td>HTTP request representation</td>\n</tr>\n<tr>\n<td><code>FormData</code></td>\n<td>Form data handling</td>\n</tr>\n<tr>\n<td><code>WebSocket</code></td>\n<td>WebSocket client</td>\n</tr>\n<tr>\n<td><code>CloseEvent</code></td>\n<td>WebSocket close event</td>\n</tr>\n<tr>\n<td><code>ErrorEvent</code></td>\n<td>WebSocket error event</td>\n</tr>\n<tr>\n<td><code>MessageEvent</code></td>\n<td>WebSocket message event</td>\n</tr>\n<tr>\n<td><code>EventSource</code></td>\n<td>Server-sent events client</td>\n</tr>\n</tbody>\n</table>",
          "displayName": "Installed Classes"
        },
        {
          "textRaw": "Using `FormData` with `fetch`",
          "name": "using_`formdata`_with_`fetch`",
          "type": "module",
          "desc": "<p>If you send a <code>FormData</code> body, use matching implementations for <code>fetch</code> and\n<code>FormData</code>.</p>\n<p>These two patterns are safe:</p>\n<pre><code class=\"language-js\">// Built-in globals from Node.js\nconst body = new FormData()\nawait fetch('https://example.com', {\n  method: 'POST',\n  body\n})\n</code></pre>\n<pre><code class=\"language-js\">// Globals installed from the undici package\nimport { install } from 'undici'\n\ninstall()\n\nconst body = new FormData()\nawait fetch('https://example.com', {\n  method: 'POST',\n  body\n})\n</code></pre>\n<p>After <code>install()</code>, <code>fetch</code>, <code>Headers</code>, <code>Response</code>, <code>Request</code>, and <code>FormData</code>\nall come from the installed <code>undici</code> package, so they work as a matching set.\n<code>WebSocket</code>, <code>CloseEvent</code>, <code>ErrorEvent</code>, <code>MessageEvent</code>, and <code>EventSource</code>\nalso come from the installed <code>undici</code> package.</p>\n<p>If you do not want to install globals, import both from <code>undici</code> instead:</p>\n<pre><code class=\"language-js\">import { fetch, FormData } from 'undici'\n\nconst body = new FormData()\nawait fetch('https://example.com', {\n  method: 'POST',\n  body\n})\n</code></pre>\n<p>Avoid mixing a global <code>FormData</code> with <code>undici.fetch()</code>, or <code>undici.FormData</code>\nwith the built-in global <code>fetch()</code>. Keeping them paired avoids surprising\nmultipart behavior across Node.js and undici versions.</p>",
          "displayName": "Using `FormData` with `fetch`"
        },
        {
          "textRaw": "Use Cases",
          "name": "use_cases",
          "type": "module",
          "desc": "<p>Global installation is useful for:</p>\n<ul>\n<li><strong>Polyfilling environments</strong> that don't have native fetch support</li>\n<li><strong>Ensuring consistent behavior</strong> across different Node.js versions</li>\n<li><strong>Library compatibility</strong> when third-party libraries expect global fetch</li>\n<li><strong>Migration scenarios</strong> where you want to replace built-in implementations</li>\n<li><strong>Testing environments</strong> where you need predictable fetch behavior</li>\n</ul>",
          "displayName": "Use Cases"
        },
        {
          "textRaw": "Example: Polyfilling an Environment",
          "name": "example:_polyfilling_an_environment",
          "type": "module",
          "desc": "<pre><code class=\"language-js\">import { install } from 'undici'\n\n// Check if fetch is available and install if needed\nif (typeof globalThis.fetch === 'undefined') {\n  install()\n  console.log('Undici fetch installed globally')\n}\n\n// Now fetch is guaranteed to be available\nconst response = await fetch('https://api.example.com')\n</code></pre>",
          "displayName": "Example: Polyfilling an Environment"
        },
        {
          "textRaw": "Example: Testing Environment",
          "name": "example:_testing_environment",
          "type": "module",
          "desc": "<pre><code class=\"language-js\">import { install } from 'undici'\n\n// In test setup, ensure consistent fetch behavior\ninstall()\n\n// Now all tests use undici's implementations\ntest('fetch API test', async () => {\n  const response = await fetch('https://example.com')\n  expect(response).toBeInstanceOf(Response)\n})\n</code></pre>",
          "displayName": "Example: Testing Environment"
        },
        {
          "textRaw": "Notes",
          "name": "notes",
          "type": "module",
          "desc": "<ul>\n<li>The <code>install()</code> function overwrites any existing global implementations</li>\n<li>Classes installed are undici's implementations, not Node.js built-ins</li>\n<li>This provides access to undici's latest fetch, WebSocket, and EventSource features and performance improvements</li>\n<li>The global installation persists for the lifetime of the process</li>\n</ul>",
          "displayName": "Notes"
        }
      ],
      "displayName": "Global Installation"
    }
  ]
}