All Projects → hatedMe → Wechat Request

hatedMe / Wechat Request

Licence: mit
🚀⚡️基于Promise实现微信小程序http请求,轻便,小巧,api友好,功能丰富

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Wechat Request

Wepy Plugin Axios
在 wepy 中使用 axios
Stars: ✭ 105 (-32.69%)
Mutual labels:  axios, wechat
Elastalert Wechat Plugin
elastalert微信企业号报警插件
Stars: ✭ 112 (-28.21%)
Mutual labels:  wechat, weixin
Request
go request, go http client
Stars: ✭ 105 (-32.69%)
Mutual labels:  axios, request
Leaf
一个开发友好、功能完备的开源微信商城框架
Stars: ✭ 102 (-34.62%)
Mutual labels:  wechat, weixin
Wx Miniprogram Boilerplate
基于Gulp微信小程序开发工作流,支持less样式编写,支持ESLint代码检查等功能
Stars: ✭ 122 (-21.79%)
Mutual labels:  wechat, weixin
Wechatswift
iOS WeChat App Written in Swift 5.0
Stars: ✭ 102 (-34.62%)
Mutual labels:  wechat, weixin
Wechat Toolbox
WeChat toolbox(微信工具箱)
Stars: ✭ 109 (-30.13%)
Mutual labels:  wechat, weixin
Wx Voice
Convert audio files between Tencent apps (Weixin / Wechat, QQ) and Silk codec with other general formats such as MP3 and M4A
Stars: ✭ 93 (-40.38%)
Mutual labels:  wechat, weixin
Wechat Proxy
微信代理服务。提供简单易用的 HTTP 接口,简化微信公众号后台开发。
Stars: ✭ 151 (-3.21%)
Mutual labels:  wechat, weixin
Rxios
A RxJS wrapper for axios
Stars: ✭ 119 (-23.72%)
Mutual labels:  axios, request
Wechat Mp Hack
微信公众平台模拟登录自动群发图文消息
Stars: ✭ 101 (-35.26%)
Mutual labels:  wechat, weixin
Wxread Webautoreader
微信读书自动阅读器,全自动刷阅读时长,轻轻松松冲顶霸榜,您的微读挂机好帮手
Stars: ✭ 138 (-11.54%)
Mutual labels:  wechat, weixin
Wechat Weapp Movie
🎬电影推荐 - 微信小程序
Stars: ✭ 1,355 (+768.59%)
Mutual labels:  wechat, weixin
Ggbot
一个用Go写的微信机器人
Stars: ✭ 103 (-33.97%)
Mutual labels:  wechat, weixin
Wechat Mall
清欢美味食光机,也是我做的第一个小程序,功能比较简单,后台基于API工厂
Stars: ✭ 98 (-37.18%)
Mutual labels:  wechat, weixin
Wechat
java微信客户端
Stars: ✭ 109 (-30.13%)
Mutual labels:  wechat, weixin
Weixin Java Mp Demo
基于Spring Boot 和 WxJava 实现的微信公众号Java后端Demo,支持多公众号
Stars: ✭ 1,291 (+727.56%)
Mutual labels:  wechat, weixin
Teepay
Typecho 个人支付宝、微信收款插件
Stars: ✭ 90 (-42.31%)
Mutual labels:  wechat, weixin
Vue Api Request
Control your API calls by using an amazing component which supports axios and vue-resource
Stars: ✭ 116 (-25.64%)
Mutual labels:  axios, request
Typescript Wxapi.d.ts
🦉微信小程序typescript的声明文件
Stars: ✭ 133 (-14.74%)
Mutual labels:  wechat, weixin

wechat-request

基于Promise微信小程序http请求,轻便,小巧,api友好,功能丰富

特别之处

  • 支持Promise API
  • 拦截请求和响应
  • 转换请求和响应数据
  • 取消请求
  • 自动转换为JSON数据
  • 超时请求
  • 告别callback
  • 支持默认请求前缀
  • 支持并发请求

使用方式

yarn add wechat-request
npm install wechat-request --save
import wxRequest from 'wechat-request';

一步上手

首先来一个简单的get请求

// 向具有给定ID的用户发出请求
wxRequest.get('/user?id=12345')
.then(function (response) {
	console.log(response);
})
.catch(function (error) {
	console.log(error);
});

// 可选地,上面的请求也可以按照
wxRequest.get('/user', {
	params: {
			id: 'number'
	}
}).then(function (response) {
    console.log(response);
}).catch(function (error) {
    console.log(error);
});

// 想要使用 async/await? 将`async`关键字添加到外部函数/method
async function getUser() {
	try {
		const response = await wxRequest.get('/user?ID=12345');
		console.log(response);
	} catch (error) {
		console.error(error);
	}
}

多种方法使用async/waait,开启代码便捷、畅快之旅

接着再来一个post请求

wxRequest.post('/user', {
	firstname : 'firstname',
	lastname : 'lastname'
}).then(function (response) {
  console.log(response);
}).catch(function (error) {
  console.log(error);
});

执行多并发请求例子

function getUserAccount() {
  return wxRequest.get('/user/12345');
}

function getUserPermissions() {
  return wxRequest.get('/user/12345/permissions');
}

wxRequest.all([getUserAccount(), getUserPermissions()])
	.then(response =>{
			// dosoming ...
	});

请求方法别名

当然除了常见的get,post其他的请求也统一封装

  • wxRequest.request(config)
  • wxRequest.get(url[, config])
  • wxRequest.delete(url[, config])
  • wxRequest.head(url[, config])
  • wxRequest.options(url[, config])
  • wxRequest.post(url[, data[, config]])
  • wxRequest.put(url[, data[, config]])
  • wxRequest.patch(url[, data[, config]])

note: 当使用别名方法url时,methoddata属性不需要在config中指定。

全局配置

使用场景用户请求需要token,或者地址前缀,一次配置,省时省心。

wxRequest.defaults.baseURL = 'https://api.example.com';
wxRequest.defaults.headers['Authorization'] = AUTH_TOKEN;
wxRequest.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

致谢 && 参考

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].