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 .formData() and its usefulness and performance in server environments. It is recommended to use a dedicated library for parsing multipart/form-data bodies, such as Busboy or @fastify/busboy.
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)