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 🙏

© 2025 – Pkg Stats / Ryan Hefner

xbot-fe-request2

v0.2.3

Published

## 背景

Downloads

7

Readme

前端网络请求库使用说明

背景

为了统一不同业务项目网络请求 本库基于 umi-requeset,结合业务项目统一业务场景封装一些通用方法 目前支持 node 与 web 环境

安装

 npm i xbot-fe-request2

支持请求 API

原始 reqest: request.request(url,params,method,options)

get 请求: request.get(url,params,options)

post 请求: request.post(url,params,options)

delete 请求: request.delete(url,params,options)

put 请求: request.put(url,params,options)

patch 请求: request.patch(url,params,options)

上传文件: request.uploadFile(url,params,options)

上传到 oss: request.uploadOSS(url,params,options)

上传到 cos: request.uploadCOS(url,params,options)

轮询请求: request.cycleRequest(url,params,cycleType,method,options)

请求配置

请求参数说明

| 参数 | 说明 | 类型 | 可选值 | 默认值 | | :-------- | :------------------------------------- | :--------------------- | :------------------- | :------- | | url | 请求地址 | string | -- | -- | | params | 请求参数 | object(key-value 形式) | -- | -- | | method | 请求方式 | string | get , post , put ... | get | | cycleType | 轮询类型,目前仅仅支持次数,咱不支持定时 | {num:number} | -- | {num:10} | | options | 请求可选参数 ,详情见下方 | options | -- | -- |

请求 options

| 参数 | 说明 | 类型 | 可选值 | 默认值 | | :--------------------- | :----------------------- | :------------------- | :----------------- | :-------- | | canUnpack | 是否支持自动解包 | boolean | boolean、undefined | undefined | | autoServiceValidate | 是否支持自动拦截业务错误 | boolean | boolean、undefined | true | | useDefaultValidate | 是否使用自动验证 | boolean | boolean、undefined | true | | customShowErrorMessage | 自定义报错 | function | -- | -- | | okCodes | 正确业务码或 http 状态码 | number[] 、 string[] | -- | | serviceErrorCodes | 业务码 | object | -- | -- | | resInterceptors | 响应拦截器 | function[] | -- | -- | | reqInterceptors | 请求拦截器 | function[] | -- | -- | | customLoading | 自定义 loading | boolean | -- | -- | | noAuthUrl | 非登陆态需要登陆地址 | string | -- | -- | | customMessage | 自定义消息实例 | MyMessage | -- | -- |

使用实例

正常使用(web或node)

import request from 'xbot-fe-request2'

request.get('xxxx', {})
  .then((res) => {
    console.log('~~~~~~ helo');
    console.log(res);
  });

完全定制message消息使用

class Tmp {
  isDomReady(){
    if (document.readyState === 'interactive' || document.readyState === 'complete') {
      return true
    }
    return false
  }
  success(p) {
    if(this.isDomReady()) message.success("success")
    console.log('success', p);
  }
  warning(p) {
    console.log('warning', p);
  }
  info(p) {
    console.log('info', p);
  }
  loading(p) {
    console.log("this.isDomReady()",this.isDomReady())
    if(this.isDomReady()) {
     console.log(document.getElementsByTagName('head')[0])
    }
    console.log('loading 1111', p);
  }
  close(p){
    console.log('close', p);
  }
}

import request from 'xbot-fe-request2'
request.setDefaultSetting({
   customMessage:new Tmp()
});

request.get('xxxx', {})
  .then((res) => {
    console.log('~~~~~~ helo');
    console.log(res);
  });

半定制message

import request from 'xbot-fe-request2'

request.setDefaultSetting({
  customLoading:true,
  customShowErrorMessage:true
});

request.get('xxxx', {})
  .then((res) => {
    console.log('~~~~~~ helo');
    console.log(res);
  });