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

babyfs-wxapp-request

v1.3.0

Published

微信小程序网络请求

Downloads

12

Readme

babyfs-wxapp-request

微信小程序网络请求封装

Build Setup

# install dependencies
npm install

# serve development program
npm run dev

# build for production
npm run build

How to use

npm install --save babyfs-wxapp-preload
// app.js
import ajax from "../babyfs-wxapp-request/index.js";

App({
  async onLaunch() {
    const options = {
      url: "api/xxx/xxx",
      data: {},
      type: ajax["TYPES"]["DEEPEST_DATA_NOT_REQUIRED"],
      individualFlag: true
    };
    let r;
    try {
      /*
       * type 类型为 ajax['TYPES']['DEEPEST_DATA_REQUIRED']     返回的r即为res.data.data
       * type 类型为 ajax['TYPES']['DEEPEST_DATA_NOT_REQUIRED'] 返回的r即为res.data
       */
      r = await ajax.GET();
    } catch (error) {
      /*
       * 失败会抛出 error code 为错误码 msg  为错误信息
       * individualFlag:false 会走默认的错误处理机制 (展示错误信息 + 上传错误日志 + code状态码对应处理)
       * individualFlag:true  开发者可根据code和msg自定义处理 默认只包含了(upload errorlog)
       */
      console.log(error);
      const { code, msg } = { ...error };
      // code handler
      switch (code) {
        case 401:
          // do someting
          break;
        default:
          // do someting
          break;
      }
    }
  }
});

GET/POST(requestHandler)

GET/POST 方法

Parameter: requestHandler(Object)

| name | type | required | default | description | value | | -------------- | ------- | -------- | ------------------------------ | -------------------------------------- | ------------------------------------------------------------------ | | url | String | yes | - | 请求地址 | - | | data | Object | yes | - | 传递参数 | {} | | type | Number | no | TYPES['DEEPEST_DATA_REQUIRED'] | 是否需要返回 res.data.data | TYPES['DEEPEST_DATA_REQUIRED']/ TYPES['DEEPEST_DATA_NOT_REQUIRED'] | | individualFlag | Boolean | no | false | 是否单独处理 server 返回的 msg 和 code | true/false |

TYPES

TYPES 类型对象

| key | value | type | description | | ------------------------- | ----- | ------ | ------------------------ | | DEEPEST_DATA_REQUIRED | 0 | Number | 接口返回 res.data.data | | DEEPEST_DATA_NOT_REQUIRED | 1 | Number | 接口不返回 res.data.data |

Notice

request header

  // request header
  {
    'content-type': 'application/x-www-form-urlencoded',
    'X-Auth-Token': token,
    'babyfs-wxapp-source': 'wxapp',
    'babyfs-wxapp-version': `${header.wxappVersion()}`,
    'babyfs-wxapp-name': `${header.wxappName()}`
  }
  1. token 取值依赖 babyfs-wxapp-storage (授权认证需要注意)
  2. babyfs-wxapp-version: 来自存储到本地的小程序版本号
  3. babyfs-wxapp-name: 来自存储到本地的小程序名称