request-pure
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.0 • Public • Published

    request-pure

    Zero-dependency, lightweight http request client for nodejs

    Install

    npm install request-pure --save
    # or
    yarn add request-pure

    Usage

    import request from 'request-pure';
    
    void (async () => {
      const url = 'https://github.com/';
      const defaultOptions = {
        method: 'GET',
        body: null,
        followRedirect: true,
        maxRedirectCount: 20,
        timeout: 0,
        size: 0,
      };
      const response = await request(url, defaultOptions);
      const text = await response.text();
    })();

    API

    request(url[, options])

    • url: Request URL

    • options: Options

      interface Options {
        /**
         * Request method
         * @default 'GET'
         */
        method?: string;
        /**
         * Request body
         * @default null
         */
        body?: string | null | Buffer | Stream;
        /**
         * Request headers
         */
        headers?: Record<string, string>;
        /**
         * Request query
         */
        query?: Record<string, string>;
        /**
         * Allow redirect
         * @default true
         */
        followRedirect?: boolean;
        /**
         * Maximum redirect count. 0 to not follow redirect
         * @default 20
         */
        maxRedirectCount?: number;
        /**
         * Request/Response timeout in ms. 0 to disable
         * @default 0
         */
        timeout?: number;
        /**
         * Maximum response body size in bytes. 0 to disable
         * @default 0
         */
        size?: number;
      }

    Response

    interface Response {
      /** Convenience property representing if the request ended normally */
      ok: boolean;
      /** Return origin stream */
      stream: Stream;
      /**
       * Download file to destination
       * @param {WriteStream} dest  Download write stream
       * @param {ProgressCallback=} onProgress Download progress callback
       */
      download: (dest: WriteStream, onProgress?: ProgressCallback) => Promise<void>;
      /** Decode response as ArrayBuffer */
      arrayBuffer(): Promise<ArrayBuffer>;
      /** Decode response as Blob */
      blob(): Promise<Blob>;
      /** Decode response as text */
      text(): Promise<string>;
      /** Decode response as json */
      json<T>(): Promise<T>;
      /** Decode response as buffer */
      buffer(): Promise<Buffer>;
    }
    
    /** Download progress information */
    interface ProgressInfo {
      /** Total file bytes */
      total: number;
      /** Delta file bytes */
      delta: number;
      /** Transferred file bytes */
      transferred: number;
      /** Transferred percentage */
      percent: number;
      /** Bytes transferred per second */
      bytesPerSecond: number;
    }

    License

    MIT License

    request-pure vs. the Competition

    Package Size
    request request package size
    superagent superagent package size
    got got package size
    axios axios package size
    isomorphic-fetch isomorphic-fetch package size
    r2 r2 package size
    node-fetch node-fetch package size
    phin phin package size
    request-pure request-pure package size

    Install

    npm i request-pure

    DownloadsWeekly Downloads

    4

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    46.4 kB

    Total Files

    7

    Last publish

    Collaborators

    • islizeqiang