Skip to content

Latest commit

 

History

History
60 lines (39 loc) · 2.51 KB

File metadata and controls

60 lines (39 loc) · 2.51 KB

Fetch

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

Documentation and examples can be found on MDN.

FormData

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.

Response

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

Request

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

Header

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

Body Mixins

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)