@tripathirajan/fetcher - v1.0.2
    Preparing search index...

    Function default

    Index

    Properties

    delete: (url: string, config?: RequestConfig) => Promise<Response>

    Type declaration

      • (url: string, config?: RequestConfig): Promise<Response>
      • Performs a DELETE request.

        Parameters

        • url: string

          The request path.

        • config: RequestConfig = {}

          Optional request configuration.

        Returns Promise<Response>

        A Promise resolving to the Response.

        fetcher.delete('/users/1')
        .then(response => console.log('Deleted successfully'))
        .catch(err => console.error(err));
    downloadWithProgress: (
        url: string,
        onProgress: (loaded: number, total: null | number) => void,
        config?: RequestConfig,
    ) => Promise<Blob>

    Type declaration

      • (
            url: string,
            onProgress: (loaded: number, total: null | number) => void,
            config?: RequestConfig,
        ): Promise<Blob>
      • Downloads a file while reporting progress.

        Parameters

        • url: string

          The request path.

        • onProgress: (loaded: number, total: null | number) => void

          Callback for download progress.

        • config: RequestConfig = {}

          Optional request configuration.

        Returns Promise<Blob>

        A Promise resolving to the downloaded Blob.

        If used in a non-browser environment.

        browser

        This method is only supported in browser environments.

        fetcher.downloadWithProgress('/file.zip', (loaded, total) => {
        const percentComplete = total ? (loaded / total) * 100 : 0;
        console.log(`Download progress: ${percentComplete}%`);
        })
        .then(blob => {
        const url = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = 'file.zip';
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        })
        .catch(err => console.error(err));
    get: (url: string, config?: RequestConfig) => Promise<Response>

    Type declaration

      • (url: string, config?: RequestConfig): Promise<Response>
      • Performs a GET request and parses JSON.

        Parameters

        • url: string

          The request path.

        • config: RequestConfig = {}

          Optional request configuration.

        Returns Promise<Response>

        A Promise resolving to the Response.

        fetcher.get('/users')
        .then(response => response.json())
        .then(data => console.log(data))
        .catch(err => console.error(err));
    interceptors: Interceptors

    post

    post: (url: string, body: unknown, config?: RequestConfig) => Promise<Response>

    Type declaration

      • (url: string, body: unknown, config?: RequestConfig): Promise<Response>
      • Performs a POST request with a JSON body.

        Parameters

        • url: string

          The request path.

        • body: unknown

          The JSON payload.

        • config: RequestConfig = {}

          Optional request configuration.

        Returns Promise<Response>

        A Promise resolving to the Response.

        fetcher.post('/users', { name: 'John Doe' })
        .then(response => response.json())
        .then(data => console.log(data))
        .catch(err => console.error(err));
    postWithUploadProgress: (
        url: string,
        body: string | Blob | FormData,
        onUploadProgress: (event: ProgressEvent) => void,
        config?: RequestConfig,
    ) => Promise<Response>

    Type declaration

      • (
            url: string,
            body: string | Blob | FormData,
            onUploadProgress: (event: ProgressEvent) => void,
            config?: RequestConfig,
        ): Promise<Response>
      • Performs a POST request with upload progress reporting using XHR.

        Parameters

        • url: string

          The request path.

        • body: string | Blob | FormData

          The payload to upload.

        • onUploadProgress: (event: ProgressEvent) => void

          Callback for upload progress.

        • config: RequestConfig = {}

          Optional request configuration.

        Returns Promise<Response>

        A Promise resolving to the Response.

        If used in a non-browser environment.

        This method is only supported in browser environments.

        browser

        fetcher.postWithUploadProgress('/upload', formData, (event) => {
        const percentComplete = (event.loaded / event.total) * 100;
        console.log(`Upload progress: ${percentComplete}%`);
        })
        .then(response => response.json())
        .then(data => console.log(data))
        .catch(err => console.error(err));
    put: (url: string, body: unknown, config?: RequestConfig) => Promise<Response>

    Type declaration

      • (url: string, body: unknown, config?: RequestConfig): Promise<Response>
      • Performs a PUT request with a JSON body.

        Parameters

        • url: string

          The request path.

        • body: unknown

          The JSON payload.

        • config: RequestConfig = {}

          Optional request configuration.

        Returns Promise<Response>

        A Promise resolving to the response.

    Methods