weapp-next
Weapp(微信小程序) official API wrapper, purpose to expose fashionable, friendly and fluent programming API.
Features
-
Promisified async API
-
Shortcuts for
wx.request
API -
Enhancements official APIs
-
RESTful http client
Install
# via Github
npm i xixilive/weapp-next --save-dev
# via npm
npm i weapp-next --save-dev
Examples
non-callback and RESTful HTTP
const weapp = wxconst client = weapp //async/await{ const code = await weapp const errMsg ...userInfo = await weapp return await client} //promise{ const getUserInfo = { return weapp
Usage
weapp-next
use UMD module system, you can load it in Commonjs or AMD format.
// get wrapped wx Objectconst request Http = // use request API // use shortcuts of request API, such as get, post, put, etc.request // use Http clientconst http = http // orconst weapp = wx
Wraps almost all of official APIs, see Wrapped methods
Enhancements
Create http request shortcuts according to wechat mini-program declared verbs(RFC 2616). specially, the PATCH
verb maybe useful for strict RESTful-ist, and so it has defined also.
weapp.request
It resolves a response which take a statusCode in range of [200, 300), and reject a response which out of the range.
The resolved response and rejected reason/error is the response object from the native wx.request
.
const request = requestrequestrequestrequestrequestrequestrequestoptionsurl:String init:Functionrequestrequest
Optional init
argument is a zero-arugments function to interpolate request parameters, and it expects to return an Object value by contract. you can override any request params by the returned object except the url
and method
.
// logic of init functionconst config = ...return ...config ... url method
weapp.requireAuth
(DPRECIATED)
DPRECIATED
Here is a Express middleware for weapp login scenario which purpose to make it easy to integrate weapp login and getUserInfo logic. express-weapp-auth
Use RESTful Http client
const http = http // /status?version=1http