TXMLHttpRequestBodyInit
Bun

type

XMLHttpRequestBodyInit

Referenced types

class Blob

A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system.

MDN Reference

  • readonly size: number
  • readonly type: string
  • Returns a promise that resolves to the contents of the blob as an ArrayBuffer

  • bytes(): Promise<Uint8Array<ArrayBufferLike>>;

    Returns a promise that resolves to the contents of the blob as a Uint8Array (array of bytes) its the same as new Uint8Array(await blob.arrayBuffer())

  • formData(): Promise<FormData>;

    Read the data from the blob as a FormData object.

    This first decodes the data from UTF-8, then parses it as a multipart/form-data body or a application/x-www-form-urlencoded body.

    The type property of the blob is used to determine the format of the body.

    This is a non-standard addition to the Blob API, to make it conform more closely to the BodyMixin API.

  • json(): Promise<any>;

    Read the data from the blob as a JSON object.

    This first decodes the data from UTF-8, then parses it as JSON.

  • start?: number,
    end?: number,
    contentType?: string
    ): Blob;
  • Returns a readable stream of the blob's contents

  • text(): Promise<string>;

    Returns a promise that resolves to the contents of the blob as a string

type BufferSource = NodeJS.TypedArray | DataView | ArrayBufferLike

class FormData

Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest.send() method. It uses the same format a form would use if the encoding type were set to "multipart/form-data".

MDN Reference

  • readonly size: number
  • [Symbol.iterator](): URLSearchParamsIterator<[string, string]>;
  • name: string,
    value: string
    ): void;

    Appends a specified key/value pair as a new search parameter.

    MDN Reference

  • name: string,
    value?: string
    ): void;

    Deletes the given search parameter, and its associated value, from the list of all search parameters.

    MDN Reference

  • entries(): URLSearchParamsIterator<[string, string]>;

    Returns an array of key, value pairs for every entry in the search params.

  • callbackfn: (value: string, key: string, parent: URLSearchParams) => void,
    thisArg?: any
    ): void;

    Iterates over each name-value pair in the query and invokes the given function.

    const myURL = new URL('https://example.org/?a=b&#x26;c=d');
    myURL.searchParams.forEach((value, name, searchParams) => {
      console.log(name, value, myURL.searchParams === searchParams);
    });
    // Prints:
    //   a b true
    //   c d true
    
    @param callbackfn

    Invoked for each name-value pair in the query

    @param thisArg

    To be used as this value for when fn is called

  • name: string
    ): null | string;

    Returns the first value associated to the given search parameter.

    MDN Reference

  • name: string
    ): string[];

    Returns all the values association with a given search parameter.

    MDN Reference

  • name: string,
    value?: string
    ): boolean;

    Returns a Boolean indicating if such a search parameter exists.

    MDN Reference

  • keys(): URLSearchParamsIterator<string>;

    Returns a list of keys in the search params.

  • name: string,
    value: string
    ): void;

    Sets the value associated to a given search parameter to the given value. If there were several values, delete the others.

    MDN Reference

  • toJSON(): Record<string, string>;
  • toString(): string;

    Returns a string containing a query string suitable for use in a URL. Does not include the question mark.

  • values(): URLSearchParamsIterator<string>;

    Returns a list of values in the search params.