npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

yangtze-request

v1.0.4

Published

yangtze common request

Downloads

72

Readme

yangtze-request

长江大数据前端通用请求方法,基于 umi-request 封装

基础功能

  1. 通用接口请求
  2. 统一错误提示方案封装
  3. 默认超时时间:3s

使用方法

  1. 引入
    npm i yangtze-request --saveyarn add yangtze-request

  2. 使用

    • 在 initRequest 方法调用前注册错误处理函数,否则仅 console.log 提示错误信息

    • 注册错误处理函数时 common 属性提供的方法即通用错误处理函数,可抛出除特殊处理方案外的全部错误信息

      import { registerErrorHandler } from 'yangtze-request';
      registerErrorHandler({
        common: ({ statusCode, statusMessage, data }) => {
          message.error(
            `${statusCode ? statusCode : '未知错误'} : ${statusMessage ? statusMessage : '请刷新页面重试'}`
          );
        },
        401: ({ statusCode, statusMessage, data }) => {
          history.push('/login');
        },
        403: () => {
          history.push('/403');
        },
      });
    • 通用实例 initRequest,传入参数

      initRequest(url, options, entendOptions)

      // get 方法
      import { initRequest } from 'yangtze-request';
      const url = '/api/user/info';
      const result = await initRequest(url, {
        method: 'get',
        params: { id: 1 },
      });
      // post 方法
      import { initRequest } from 'yangtze-request';
      const url = '/api/user/add';
      const result = await initRequest(url, {
        method: 'post',
        data: { name: 'oo' },
      });
      // 通用文件上传
      import { initRequest } from 'yangtze-request';
      const url = '/api/upload';
      const formData = new FormData();
      formData.append('file', file);
      const result = await initRequest(url, {
        method: 'post',
        requestType: 'form',
        data: formData,
      });
      // 二进制流
      import { initRequest } from 'yangtze-request';
      const url = '/api/download';
      const result = await initRequest(url, {
        method: 'get',
        params: { bucketName: '', filename: '' },
        responseType: 'blob',
      });
    • 如有扩展请求实例通用配置的需要

      • 1、使用 initRequest.extendOptions 方法补充默认实例配置
      import { initRequest } from 'yangtze-request';
      initRequest.extendOptions({
        headers: {
          platform: 'macOS',
        },
        timeout: 5000,
      });
      export default initRequest;
      • 2、使用 createInstance 创建新实例
      import { createInstance } from 'yangtze-request';
      const extendOptions = {
        headers: {
          platform: 'macOS',
        },
        timeout: 5000,
      };
      const request = createInstance(extendOptions);
      export default request;
    • 更多功能拓展请参考 umi-request

版本信息

| 版本号 | 更新日期 | 更新内容 | | ------ | ---------- | ---------------------------------- | | v0.1.0 | 2022-08-04 | 封装统一错误处理逻辑的统一请求方案 | | v0.2.0 | 2022-08-30 | 增加文件上传下载 | | v0.3.0 | 2022-08-30 | 增加文件流默认处理 | | v1.0.0 | 2022-09-05 | 调整统一数据格式 | | v1.0.2 | 2022-09-15 | 调整扩展配置方案 | | v1.0.3 | 2022-09-20 | 增加扩展实例 | | v1.0.4 | 2022-09-22 | 下载文件名解码 |