Interface RequestOptions

Here you can provide request options including headers. If you want to set some options globally, use defineKnorryOptions({ ... })

Hierarchy

  • RequestOptions

Properties

XHRClass?: Function | XMLHttpRequest

You can optionally provide a XHRClass, which can be useful when using node.js

Default

XMLHttpRequest
auth?: {
    password?: null | string;
    username?: null | string;
}

If you want to use http authentification, provide your details here

Type declaration

  • Optional password?: null | string
  • Optional username?: null | string
dataType?: "text" | "formdata" | "json" | "urlencoded"

Gives knorry a hint on which type of data you want to send. Not necessary but recommended. If data is a plain Object and no instance of FormData, URLSearchParams or Blob this will default to 'json'

Default

'text'
easyMode?: boolean

Indicates wether the response should be an response object or an extended primitive type

Default

true
headers?: {
    [key: string]: string;
}

Provide you headers here NOTE: Header don't use camelcase, you might have to use quotes like in this example:

Example

{
* 'Content-Type': 'application/json'
* }

Type declaration

  • [key: string]: string
timeout?: number

Specifies the timeout for the request in ms When set to 0 or undefined no timeout will be used

upload?: {
    end?(success) => void;
    progress?(percentage, loaded, total) => void;
    start?(total) => void;
}

Here you can optionally provide event handlers fo file uploads

Type declaration

  • end?:function
    • An event handler function which is called at the end of a file upload

      Parameters

      • success: boolean

        Indicates whether the upload was sucessful or not

      Returns void

  • progress?:function
    • An event handler function which is called everytime upload progress was made

      Parameters

      • percentage: number

        A number between 0 and 1 indicating how much progress was already made

      • loaded: number

        Already uploaded bytes

      • total: number

        Total file size in bytes

      Returns void

  • start?:function
    • An event handler function which is called at the beginning of a file upload

      Parameters

      • total: number

        Total file size in bytes

      Returns void

withCredentials?: boolean

States wether credentials should bei included or not

Default

true

Methods

  • This gives you the option to change the XHR before send

    Parameters

    • xhr: XMLHttpRequest

      The original XHR

    Returns void | XMLHttpRequest

    The modfied XHR or void

  • If you want to, you can define an error handler here. If a error handler is defined in the options, your promise won't reject anymore

    Parameters

    • err: any

      The error that occured

    • resolve: Function

      Gives you the option to resolve the promise with a specified value

    Returns void

  • Optional function which gets called everytime fetching progress was made

    Parameters

    • percentage: number

      A number ranging from 0 to 1 telling you what percentage of the request was already loaded

    Returns void

Generated using TypeDoc