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

wpm-fetch

v0.0.2

Published

微信小程序,请求封装,实现可配置的请求,使用promise进行封装

Downloads

1

Readme

WPM-fetch

wpm-fetch 主要是适用于微信小程序的npm包 对原生微信小程序wx.request 进行promise封装。 借鉴于axios ,实现axios 的大部分配置,例:method,baseURL,headers,params,data,validateStatus,transformRequest,transformResponse等配置,后续将持续更新实现更多配置。

安装

npm install wpm-fetch --save
cnpm install wpm-fetch --save

引用

import fetch from 'wpm-fetch';
const fetch = require("wpm-fetch").default;

示例

fetch.get(url[,data,config])
fetch.post(url[,data,config])
fetch.put(delete[,data,config])
fetch.head(url[,data,config])
fetch.trace(url[,data,config]) 
fetch.connect(url[,data,config])

以上方法名对应着相对的请求方式

fetch.request({url[,method,data,params,headers]})

<!-- get 请求: /get/user/info?urlparams=1&id=1&params=2  -->
fetch.get('/get/user/info?urlparams=1',{id:1},{params:{params=2}})
  .then( response=> {
    console.log(response); 
  })
  .catch( error=> {
    console.log(error); 
  });
<!-- post 请求:  -->
fetch.post('/get/user/info?urlparams=1',{id:1},{params:{params=2}})
  .then( response=> {
    console.log(response); 
  })
  .catch( error=> {
    console.log(error); 
  });
<!-- put 请求:  -->
fetch.put('/get/user/info?urlparams=1',{id:1},{params:{params=2}})
  .then( response=> {
    console.log(response); 
  })
  .catch( error=> {
    console.log(error); 
  });
  <!-- head 请求:  -->
fetch.head('/get/user/info?urlparams=1',{id:1},{params:{params=2}})
  .then( response=> {
    console.log(response); 
  })
  .catch( error=> {
    console.log(error); 
  });
  <!-- trace 请求:  -->
fetch.trace('/get/user/info?urlparams=1',{id:1},{params:{params=2}})
  .then( response=> {
    console.log(response); 
  })
  .catch( error=> {
    console.log(error); 
  });
  <!-- connect 请求:  -->
fetch.connect('/get/user/info?urlparams=1',{id:1},{params:{params=2}})
  .then( response=> {
    console.log(response); 
  })
  .catch( error=> {
    console.log(error); 
  });

简介

wpm-fetch 可单独引入 直接fetch 调用所有内置方法 也可以挂载再wpm-wx依赖中, 内置支持wpm 引入方式

import fetch from 'wpm-fetch';
import wpm from 'wpm-wx';

wpm.use(fetch);

new  wpm();

这样引入后即可在微信小程序page实例中this.$fetch.get() 中使用 ps: 如果不用用$fetch 作为 请求名 可以 wpm.prototype.xxxx = fetch;

api

{
  method:"", // 默认请求方式 默认是get
  baseURL:"", // 默认 请求域名
  headers:{}, // 发送的自定义请求头
  params:{}, // 是与请求一起发送的 URL 参数 params 现只支持对象形式
  data: {},  // 是与请求一起发送的 body 里面的内容
  /**
    * 注册请求前预处理
    * 还可以通过  fetch.interceptors.request.use(config=>{}) 实现注册
    */
  transformRequest(config=>{
     // 实现内容
  }) , 
  /**
    * 注册请求拦截器
    * 还可以通过  fetch.interceptors.response.use(config=>{},error=>{}) 实现注册
    */
  transformResponse(data=>{
     // 实现内容
  },error=>{
    // 请求错误/失败 实现内容
  }) , 
   
}

版本

  • alpha v0.0.1

    使用ts 重构,重新规划拦截器和项目结构 缩减原项目实现过多的冗余的功能,尽量精简 实现 基本请求封装,公共配置实现

  • alpha v0.0.2

    1.项目关联github