On this page

Undici exposes a fetch() method starts the process of fetching a resource from the network.

Documentation and examples can be found on MDN.

This API is implemented as per the standard, you can find documentation on MDN.

If any parameters are passed to the FormData constructor other than undefined, an error will be thrown. Other parameters are ignored.

When you use FormData as a request body, keep fetch and FormData from the same implementation. Use the built-in global FormData with the built-in global fetch(), and use undici's FormData with undici.fetch().

If you want the installed undici package to provide the globals, call install() so fetch, Headers, Response, Request, and FormData are installed together as a matching set.

This API is implemented as per the standard, you can find documentation on MDN

This API is implemented as per the standard, you can find documentation on MDN

This API is implemented as per the standard, you can find documentation on MDN

Response and Request body inherit body mixin methods. These methods include:

There is an ongoing discussion regarding body.formData() and its usefulness, performance, and security in server environments. Calling body.formData() causes undici to buffer and parse the entire body. Because multipart parsing has inherent security risks, body.formData() must only be called on responses from trusted servers.

For responses from untrusted or user-controlled servers, use a dedicated streaming library for parsing multipart/form-data bodies, such as Busboy or @fastify/busboy, and apply application-specific limits.

These libraries can be interfaced with fetch with the following example code:

import { Busboy } from '@fastify/busboy'
import { Readable } from 'node:stream'

const response = await fetch('...')
const busboy = new Busboy({
  headers: {
    'content-type': response.headers.get('content-type')
  }
})

Readable.fromWeb(response.body).pipe(busboy)