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

@xixilive/weapp-fetch

v0.1.3

Published

A fetch-like API for wechat mini-program

Downloads

7

Readme

A fetch-like API for wechat mini-program

Travis (.org) branch npm bundle size npm (scoped) Known Vulnerabilities NPM

Installation

# 小程序开发者工具构建npm包时仅处理production依赖,因此要加`--save-prod`
npm i @xixilive/weapp-fetch --save-prod

Usage

basic

A simple example of use fetch function, see API section in document for details.

import fetch from '@xixilive/weapp-fetch'

fetch('http://example.com').then(res => console.log(res))

use http

It exposes a http wrapper for wx.request.

import {http, Logger} from '@xixilive/weapp-fetch'

http.logger = new Logger(console, 'debug')

// intercept request
http.before = (params) => {
  params.someKey = 'someValue'
}

// intercept response
http.after = (res) => {
  res.someKey = 'someValue'
}

const client = http('https://example.com')

client.get('/api').then(console.log)
client.head('/api').then(console.log)
client.post('/api', data).then(console.log)
client.put('/api', data).then(console.log)
client.patch('/api', data).then(console.log)
client.delete('/api').then(console.log)

config http.logger

by default, http.logger will log nothing, see API section for details.

import fetch, {http, Logger} from '@xixilive/weapp-fetch'

// use wx RealtimeLogManager
const realtimeTransport = wx.getRealtimeLogManager()
http.logger = new Logger(realtimeTransport, 'debug')

// or use wx LogManager
const localTransport = wx.getLogManager()
http.logger = new Logger(localTransport, 'debug')

// or use wx console
const consoleTransport = console
http.logger = new Logger(consoleTransport, 'debug')

// ...
// will process logging during fetch/http requests

Build Tips

This package was prebuilt as es module to dist folder, and all of source code not be transpiled to ES5 version. If you use this package's default build, you should turn on the ES6 to ES5 option in devtools. If you want a custom build, please clone this repo.

API

fetch function

function fetch(url: string, init: any): Promise<any>;

http

// to create an http instance
function http(base: string, defaultHeaders: object): HttpInstance

interface HttpInstance {
  get(path: string, header:any): Promise<any>;
  head(path: string, header:any): Promise<any>;
  post(path: string, data: any, header: any): Promise<any>;
  put(path: string, data: any, header: any): Promise<any>;
  patch(path: string, data: any header: any): Promise<any>;
  delete(path: string, header: any): Promise<any>;
}

class http {
  // to send a request directly
  static request(options: wxRequestOptions): Promise<any>;

  // get or set logger
  static logger: Logger;

  // get or set request interpolator
  static before: RequestInterpolator;

  // get or set response interpolator
  static after: ResponseInterpolator;
}

function RequestInterpolator(params: object): void;
function ResponseInterpolator(response: object): void;

Logger

interface transport {
  // basic method
  log(...args: string[]): void;
  // level relative methods
  debug?(...args: string[]): void;
  info?(...args: string[]): void;
  warn?(...args: string[]): void;
  error?(...args: string[]): void;
}

class Logger {
  constructor(transport: Transport, level: LoggerLevel = LoggerLevel.DEBUG);
  log(level: string, ...args: string[]): Logger;
  debug(...args: string[]): Logger;
  info(...args: string[]): Logger;
  warn(...args: string[]): Logger;
  error(...args: string[]): Logger;

  static levels :LoggerLevel;
}

enum LoggerLevel {
  ERROR = 1,
  WARN = 2,
  INFO = 4,
  DEBUG = 8,
}

Incompatible features of fetch

  • Does not support FormData
  • Does not support Blob
  • Does not support abort yet