{
  "type": "module",
  "source": "doc/api/gettingstarted.md",
  "modules": [
    {
      "textRaw": "Getting Started",
      "name": "getting_started",
      "type": "module",
      "modules": [
        {
          "textRaw": "Installation",
          "name": "installation",
          "type": "module",
          "desc": "<pre><code class=\"language-bash\">npm install undici\n</code></pre>",
          "displayName": "Installation"
        },
        {
          "textRaw": "Fetch",
          "name": "fetch",
          "type": "module",
          "desc": "<p>The quickest way to get started is with <code>fetch</code>, which follows the\n<a href=\"https://fetch.spec.whatwg.org/\">Fetch Standard</a> and works the same way as\nthe browser API:</p>\n<pre><code class=\"language-js\">import { fetch } from 'undici'\n\nconst res = await fetch('https://example.com')\nconst data = await res.json()\nconsole.log(data)\n</code></pre>",
          "modules": [
            {
              "textRaw": "Using the Request object",
              "name": "using_the_request_object",
              "type": "module",
              "desc": "<p>undici also exports a <code>Request</code> class that follows the Fetch Standard:</p>\n<pre><code class=\"language-js\">import { fetch, Request } from 'undici'\n\nconst req = new Request('https://example.com', {\n  method: 'POST',\n  headers: { 'content-type': 'application/json' },\n  body: JSON.stringify({ hello: 'world' })\n})\nconst res = await fetch(req)\nconsole.log(res.status)\n</code></pre>",
              "displayName": "Using the Request object"
            },
            {
              "textRaw": "Streaming the response",
              "name": "streaming_the_response",
              "type": "module",
              "desc": "<p><code>res.body</code> is a web <code>ReadableStream</code>. Use <code>pipeline</code> from\n<code>node:stream/promises</code> to stream it to a file:</p>\n<pre><code class=\"language-js\">import { fetch } from 'undici'\nimport { pipeline } from 'node:stream/promises'\nimport { createWriteStream } from 'node:fs'\n\nconst res = await fetch('https://example.com/large-file.zip')\nawait pipeline(res.body, createWriteStream('./file.zip'))\n</code></pre>\n<blockquote>\n<p>Always consume or cancel the response body. In Node.js, garbage collection\nis not aggressive enough to release connections promptly, so leaving a body\nunread can cause connection leaks and stalled requests. See\n<a href=\"/docs/#garbage-collection\">Specification Compliance - Garbage Collection</a>\nfor details.</p>\n</blockquote>\n<p>For more on <code>fetch</code>, see <a href=\"/docs/docs/api/Fetch.html\">API Reference: Fetch</a>.</p>",
              "displayName": "Streaming the response"
            }
          ],
          "displayName": "Fetch"
        },
        {
          "textRaw": "Dispatchers: Connection reuse and pooling",
          "name": "dispatchers:_connection_reuse_and_pooling",
          "type": "module",
          "desc": "<p>By default, <code>fetch</code>, <code>request</code>, <code>stream</code>, and <code>pipeline</code> create a new connection\nfor each call. For applications that make many requests to the same origin,\nthis is wasteful. undici provides <strong>dispatchers</strong> that manage connections\ninternally.</p>",
          "modules": [
            {
              "textRaw": "`Agent` — for requests to multiple origins",
              "name": "`agent`_—_for_requests_to_multiple_origins",
              "type": "module",
              "desc": "<p><code>Agent</code> is the most general-purpose dispatcher. It pools connections per-origin\nand is the recommended default for most applications. Use it with\n<code>setGlobalDispatcher</code> to affect all undici calls globally:</p>\n<pre><code class=\"language-js\">import { Agent, setGlobalDispatcher, fetch } from 'undici'\n\nconst agent = new Agent({\n  keepAliveTimeout: 30_000,\n  keepAliveMaxTimeout: 600_000\n})\nsetGlobalDispatcher(agent)\n\n// All subsequent fetch/request/stream/pipeline calls reuse connections\nconst res = await fetch('https://api.example.com/data')\n</code></pre>\n<p>You can also pass a dispatcher per-request:</p>\n<pre><code class=\"language-js\">await fetch('https://api.example.com/data', { dispatcher: agent })\n</code></pre>",
              "displayName": "`Agent` — for requests to multiple origins"
            },
            {
              "textRaw": "`Pool` — for requests to a single origin",
              "name": "`pool`_—_for_requests_to_a_single_origin",
              "type": "module",
              "desc": "<p><code>Pool</code> manages a fixed set of connections to one origin. It gives you explicit\ncontrol over concurrency:</p>\n<pre><code class=\"language-js\">import { Pool, request } from 'undici'\n\nconst pool = new Pool('https://api.example.com', { connections: 10 })\n\nconst { body } = await request('https://api.example.com/data', {\n  dispatcher: pool\n})\nconst data = await body.json()\n\npool.close()\n</code></pre>",
              "displayName": "`Pool` — for requests to a single origin"
            },
            {
              "textRaw": "`Client` — for a single connection",
              "name": "`client`_—_for_a_single_connection",
              "type": "module",
              "desc": "<p><code>Client</code> maps to a single TCP connection. It supports pipelining (sending\nmultiple requests before responses arrive):</p>\n<pre><code class=\"language-js\">import { Client } from 'undici'\n\nconst client = new Client('https://api.example.com', {\n  pipelining: 5\n})\n\nconst { body } = await client.request({ path: '/', method: 'GET' })\nawait body.dump()\n\nclient.close()\n</code></pre>\n<p>For more on dispatcher options and lifecycle, see:</p>\n<ul>\n<li><a href=\"/docs/docs/api/Agent.html\">API Reference: Agent</a></li>\n<li><a href=\"/docs/docs/api/Pool.html\">API Reference: Pool</a></li>\n<li><a href=\"/docs/docs/api/Client.html\">API Reference: Client</a></li>\n</ul>",
              "displayName": "`Client` — for a single connection"
            }
          ],
          "displayName": "Dispatchers: Connection reuse and pooling"
        },
        {
          "textRaw": "Timeouts",
          "name": "timeouts",
          "type": "module",
          "desc": "<p>undici applies timeouts at two levels:</p>\n<ul>\n<li><strong><code>headersTimeout</code></strong> — time to wait for response headers (default: 300s).</li>\n<li><strong><code>bodyTimeout</code></strong> — time between consecutive body chunks (default: 300s).</li>\n</ul>\n<p>Set these on the dispatcher or per-request:</p>\n<pre><code class=\"language-js\">import { Agent, setGlobalDispatcher } from 'undici'\n\nconst agent = new Agent({\n  headersTimeout: 5_000,\n  bodyTimeout: 30_000\n})\n\nsetGlobalDispatcher(agent)\n</code></pre>\n<p>Timeout errors are thrown as <code>HeadersTimeoutError</code> and <code>BodyTimeoutError</code>.\nSee <a href=\"/docs/docs/api/Errors.html\">API Reference: Errors</a> for the full list.</p>",
          "displayName": "Timeouts"
        },
        {
          "textRaw": "Error handling",
          "name": "error_handling",
          "type": "module",
          "desc": "<p>undici exposes structured errors via <code>error.code</code>:</p>\n<pre><code class=\"language-js\">import { request, errors } from 'undici'\n\ntry {\n  const { body } = await request('https://example.com')\n  await body.json()\n} catch (err) {\n  switch (err.code) {\n    case 'UND_ERR_CONNECT_TIMEOUT':\n      console.error('Connection timed out')\n      break\n    case 'UND_ERR_HEADERS_TIMEOUT':\n      console.error('Headers timed out')\n      break\n    case 'UND_ERR_BODY_TIMEOUT':\n      console.error('Body timed out')\n      break\n    case 'UND_ERR_ABORTED':\n      console.error('Request was aborted')\n      break\n    default:\n      console.error(err)\n  }\n}\n</code></pre>",
          "modules": [
            {
              "textRaw": "Aborting requests",
              "name": "aborting_requests",
              "type": "module",
              "desc": "<pre><code class=\"language-js\">import { request } from 'undici'\n\nconst ac = new AbortController()\n\nsetTimeout(() => ac.abort(), 1000)\n\ntry {\n  const { body } = await request('https://example.com', {\n    signal: ac.signal\n  })\n  await body.dump()\n} catch (err) {\n  console.error(err.code) // UND_ERR_ABORTED\n}\n</code></pre>",
              "displayName": "Aborting requests"
            }
          ],
          "displayName": "Error handling"
        },
        {
          "textRaw": "Common patterns",
          "name": "common_patterns",
          "type": "module",
          "modules": [
            {
              "textRaw": "Proxies",
              "name": "proxies",
              "type": "module",
              "desc": "<p>Use <code>ProxyAgent</code> for HTTP(S) proxies, or <code>EnvHttpProxyAgent</code> to pick up\nproxy settings from environment variables:</p>\n<pre><code class=\"language-js\">import { ProxyAgent, setGlobalDispatcher } from 'undici'\n\nconst proxy = new ProxyAgent('http://proxy.internal:8080')\nsetGlobalDispatcher(proxy)\n</code></pre>\n<p>See <a href=\"/docs/docs/best-practices/proxy.html\">Best Practices: Proxy</a> and\n<a href=\"/docs/docs/api/ProxyAgent.html\">API Reference: ProxyAgent</a>.</p>",
              "displayName": "Proxies"
            },
            {
              "textRaw": "Mocking in tests",
              "name": "mocking_in_tests",
              "type": "module",
              "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('https://api.example.com')\nmockPool.intercept({ path: '/users' }).reply(200, [{ id: 1 }])\n\nconst { body } = await request('https://api.example.com/users')\nconsole.log(await body.json())\n</code></pre>\n<p>See <a href=\"/docs/docs/best-practices/mocking-request.html\">Best Practices: Mocking Request</a>\nand <a href=\"/docs/docs/api/MockAgent.html\">API Reference: MockAgent</a>.</p>",
              "displayName": "Mocking in tests"
            },
            {
              "textRaw": "Testing with undici",
              "name": "testing_with_undici",
              "type": "module",
              "desc": "<p>For test suites, set short keep-alive timeouts to avoid slow teardowns:</p>\n<pre><code class=\"language-js\">import { Agent, setGlobalDispatcher } from 'undici'\n\nconst agent = new Agent({\n  keepAliveTimeout: 10,\n  keepAliveMaxTimeout: 10\n})\nsetGlobalDispatcher(agent)\n</code></pre>\n<p>See <a href=\"/docs/docs/best-practices/writing-tests.html\">Best Practices: Writing Tests</a>.</p>",
              "displayName": "Testing with undici"
            },
            {
              "textRaw": "Customizing the global fetch",
              "name": "customizing_the_global_fetch",
              "type": "module",
              "desc": "<p>You can override Node.js's built-in globals with <code>install()</code>:</p>\n<pre><code class=\"language-js\">import { install } from 'undici'\n\ninstall()\n\n// Global fetch, Headers, Response, Request, and FormData\n// now come from undici, not the Node.js bundle\nconst res = await fetch('https://example.com')\n</code></pre>\n<p>See <a href=\"/docs/docs/api/GlobalInstallation.html\">API Reference: Global Installation</a>.</p>",
              "displayName": "Customizing the global fetch"
            }
          ],
          "displayName": "Common patterns"
        },
        {
          "textRaw": "Further reading",
          "name": "further_reading",
          "type": "module",
          "desc": "<ul>\n<li><a href=\"/docs/docs/best-practices/undici-vs-builtin-fetch.html\">Undici vs. Built-in Fetch</a> —\nwhen to install undici vs using Node.js built-in fetch</li>\n<li><a href=\"/docs/docs/api/Dispatcher.html\">API Reference</a> — full dispatcher API documentation</li>\n<li><a href=\"/docs/examples/\">Examples</a> — runnable code examples</li>\n</ul>",
          "displayName": "Further reading"
        }
      ],
      "displayName": "Getting Started"
    }
  ]
}