Interface FormUrlAddon

interface FormUrlAddon {
    formUrl<T, C, R>(this: T & Wretch<T, C, R>, input: string | object): this;
}

Methods

Methods

  • Converts the input parameter to an url encoded string and sets the content-type header and body. If the input argument is already a string, skips the conversion part.

    const form = { a: 1, b: { c: 2 } };
    const alreadyEncodedForm = "a=1&b=%7B%22c%22%3A2%7D";

    // Automatically sets the content-type header to "application/x-www-form-urlencoded"
    wretch("...").addon(FormUrlAddon).formUrl(form).post();
    wretch("...").addon(FormUrlAddon).formUrl(alreadyEncodedForm).post();

    Type Parameters

    Parameters

    • this: T & Wretch<T, C, R>
    • input: string | object

      An object to convert into an url encoded string or an already encoded string

    Returns this