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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gravityjs/wxaxios

v0.1.2

Published

基于Promise封装的wx.request请求的http客户端

Downloads

1

Readme

wxaxios

An Axios-API like Request Package for MiniProgram

wxaxios 接口请求

针对 wx.request 接口进行二次封装。

  • [x] 使用promise调用风格
  • [x] 加入拦截器功能
  • [x] api方法与axios一致
  • [x] 解除并发请求限制为10
  • [x] cookie处理

使用方式

直接npm安装

npm install @gravityjs/wxaxios -S

然后使用微信开发者工具的构建npm功能

或者直接从@gravityjs/wxaxios包的dist文件中中复制相关类型的js文件放入自己的小程序项目中

目前编译的导出文件有四种:

  • wxaxios.common.js
  • wxaxios.common.min.js
  • wxaxios.esm.js
  • wxaxios.esm..min.js

API

  1. wxaxios(config)

    wxaxios({
        url: 'http://localhost/api',
        method: 'post',
        data: {
            test: '1'
        }
    }).then(function (response) {
        console.log(response);
    });
  2. wxaxios(url[, config])

    wxaxios(
        'http://localhost/api',
        {
            method: 'post',
            data: {
                test: '1'
            }
        }
    ).then(function (response) {
        console.log(response);
    });
  3. 请求 别名

    1. wxaxios.request(config)
    2. wxaxios.get(url, data[, config])
    3. wxaxios.post(url, data[, config])
    4. wxaxios.delete(url, data[, config])
    5. wxaxios.head(url, data[, config])
    6. wxaxios.put(url, data[, config])
  4. wxaxios.create([defaultConfig])

    通过 wxaxios.create([defaultConfig]) 创建一个全新的 wxios实例。

    var instance = wxaxios.create({
        baseURL: 'http://localhost'
    });

    新实例拥有 wxaxios 下挂载的所有request方法。

  5. 请求拦截器

    request拦截器 : wxaxios.interceptors.request

    // 添加一个拦截器
    // 同时返回一个 拦截器标识
    var interceptorId = wxaxios.interceptors.request.use(function(config) {
        // do something...
        // TODO:
        // 每个拦截器都必须返回 config
        return config;
    });
    // 删除一个拦截器
    wxaxios.interceptors.request.eject(interceptorId);

    response拦截器 : wxaxios.interceptors.response

    // 添加一个拦截器
    // 同时返回一个 拦截器标识
    var interceptorId = wxaxios.interceptors.response.use(function(response) {
        // do something...
        // TODO:
        // 每个拦截器都必须返回 response
        return response;
    });
    // 删除一个拦截器
    wxaxios.interceptors.response.eject(interceptorId);
  6. Default Config

    {
        // 公共接口前缀
        baseURL: '',
        // 公共 headers 配置
        headers: {},
        // 接口超时时间, 单位 ms, 默认为 0,不做超时处理
        timeout: 0
    }
    wxaxios.defaults.baseURL = 'http://localhost';
    wxaxios.defaults.headers.common['content-type'] = 'application/json';
    wxaxios.default.headers.post['content-type'] = 'application/json';
  7. Concurrency

    {
      concurrency: 10
    }

    支持突破小程序wx.request最大并发限制是 10 个

  8. Cookie

    {
      getCookie: () => {}
    }

    可以在配置中放入getCookie函数, 方便发送请求时将存入缓存的数据放入Cookie头字段发出

借鉴项目