{"_id":"@allez/weapp-request","_rev":"2-119a61f0896a13bbb1a3e2d767412373","name":"@allez/weapp-request","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@allez/weapp-request","version":"1.0.0","description":"**参考了 Axios，用于微信小程序发起网络请求。**","main":"index.js","keywords":["weapp","request","小程序","网络请求","微信小程序","miniapp"],"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"","license":"ISC","_id":"@allez/weapp-request@1.0.0","_nodeVersion":"18.19.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-UAoRnETjVkCQ2yjh/cMWQ89Fl+0GdpJ/m5GccCho26BoYZbBLHfP8wjzRluanVAYc+E9lCRvsYCXzuasu57AQQ==","shasum":"dc28834ad5674929c3a1789dc310b3a61acdd274","tarball":"https://registry.npmjs.org/@allez/weapp-request/-/weapp-request-1.0.0.tgz","fileCount":3,"unpackedSize":36797,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHkE43q6SsFRZr7sS+S+6zu2dFCFhCNLM3dyFEIeItLnAiAvqM0EY5JmUVKplxqhPAWfLVh5KRzcIJq52D2mz0PN4Q=="}]},"_npmUser":{"name":"allez","email":"1198558672@qq.com"},"directories":{},"maintainers":[{"name":"allez","email":"1198558672@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/weapp-request_1.0.0_1702455421601_0.9121637049591975"},"_hasShrinkwrap":false},"1.0.1":{"name":"@allez/weapp-request","version":"1.0.1","description":"**参考了 Axios，用于微信小程序发起网络请求。**","main":"index.js","keywords":["weapp","request","小程序","网络请求","微信小程序","miniapp"],"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"","license":"ISC","_id":"@allez/weapp-request@1.0.1","_nodeVersion":"18.19.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-x2ACbe2vLBsOKjZh37OqNJg+G4fwiOOp0+wVfmx4r1YP8BSHKSyX62U92dKmKnPTJ9kkhbUyVfOOHWJ288K6Wg==","shasum":"21e39835ff112df1ba04ca1a37bc18b51d7daf64","tarball":"https://registry.npmjs.org/@allez/weapp-request/-/weapp-request-1.0.1.tgz","fileCount":3,"unpackedSize":36835,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH079Sqd/Fk5ruqLbnOpaYsQH+kYd0gRZUNUlHuABXqcAiEA0gXVpaZF3B4bU5XYqEVse04oAPdZIiA7vuZoDmV7bH4="}]},"_npmUser":{"name":"allez","email":"1198558672@qq.com"},"directories":{},"maintainers":[{"name":"allez","email":"1198558672@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/weapp-request_1.0.1_1702459925007_0.22721414571139564"},"_hasShrinkwrap":false},"1.0.2":{"name":"@allez/weapp-request","version":"1.0.2","description":"**参考了 Axios，用于微信小程序发起网络请求。**","main":"index.js","keywords":["weapp","request","小程序","网络请求","微信小程序","miniapp"],"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"","license":"ISC","_id":"@allez/weapp-request@1.0.2","_nodeVersion":"18.19.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-gOVydXyW+bAWTArM4wL9/IAtCZG6DIe4Gtb7u8ZIASHggorlcb41ZQkeL4GEHbxlRBjNmmhqikQWybPPDnpxJA==","shasum":"d94226f2f3d9760e7f1134250a4afb2a695e08c0","tarball":"https://registry.npmjs.org/@allez/weapp-request/-/weapp-request-1.0.2.tgz","fileCount":3,"unpackedSize":36851,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDO/58mHaOUBzcAsOGEOtn5eH+jHGul4nwWk/pJpSIQHAiB/Z9EGKafcAga1MCv099oqyIp6WggOwFMQZ9yh0vQiHQ=="}]},"_npmUser":{"name":"allez","email":"1198558672@qq.com"},"directories":{},"maintainers":[{"name":"allez","email":"1198558672@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/weapp-request_1.0.2_1702520130414_0.723108479914145"},"_hasShrinkwrap":false}},"time":{"created":"2023-12-13T08:17:01.450Z","1.0.0":"2023-12-13T08:17:01.829Z","modified":"2023-12-14T02:15:30.815Z","1.0.1":"2023-12-13T09:32:05.247Z","1.0.2":"2023-12-14T02:15:30.631Z"},"maintainers":[{"name":"allez","email":"1198558672@qq.com"}],"description":"**参考了 Axios，用于微信小程序发起网络请求。**","keywords":["weapp","request","小程序","网络请求","微信小程序","miniapp"],"license":"ISC","readme":"# Weapp Request\n\n**参考了 Axios，用于微信小程序发起网络请求。**\n\n[Axios 官方文档](http://www.axios-js.com/)\n\n## 特性\n\n- 支持 Promise API\n- 拦截请求和响应\n- 封装 wx.request\\wx.uploadFile\\wx.downloadFile\\wx.connectSocket，一致的语法结构\n- 处理 Task 任务对象\n- 非 `release` 环境支持请求体的本地打印以及本地日志记录\n\n## 发起 wx.request 请求（默认为GET请求）\n\n```javascript\nimport request from '@allez/weapp-request'\n\nrequest.request('/user/12345')\n\nrequest.request({ method: 'post', url: '/user/12345', data: { firstName: 'Fred' } })\n```\n\n### 使用别名\n\n```javascript\nrequest.request(config)\n\nrequest.get(url[, data[, config]])\n\nrequest.delete(url[, data[, config]])\n\nrequest.head(url[, data[, config]])\n\nrequest.options(url[, data[, config]])\n\nrequest.post(url[, data[, config]])\n\nrequest.put(url[, data[, config]])\n\nrequest.patch(url[, data[, config]])\n```\n\n## 发起 wx.uploadFile 请求\n\n```javascript\n// 传入 name 以及 filePath 参数会自动发起 wx.uploadFile 请求\nrequest({ url: 'www.abc.com', name: 'name', filePath: 'filePath' })\n```\n\n### 使用别名\n\n```javascript\nrequest.uploadFile('www.abc.com', 'filePath', 'name', {...config})\n\nrequest.uploadFile({ url: 'www.abc.com', filePath: 'filePath', name: 'name', ...config })\n```\n\n## 发起 wx.downloadFile 请求\n\n```javascript\n// 传入 filePath 参数会自动发起 wx.downloadFile 请求（wx.downloadFile中的 filePath 为非必填项，可传入空值）\nrequest({ url: 'www.abc.com', filePath: '' })\n```\n\n### 使用别名\n\n```javascript\nrequest.downloadFile('www.abc.com', 'filePath', {...config})\n\nrequest.downloadFile({ url: 'www.abc.com', filePath: 'filePath', ...config })\n```\n\n## 发起 wx.connectSocket 请求\n\n```javascript\nrequest.connectSocket('www.abc.com', {...config})\n\nrequest.connectSocket({ url: 'www.abc.com', ...config })\n```\n\n## 拦截请求和响应\n\n```javascript\nrequest.interceptors.request.use(function (config) {\n  // 在发送请求之前做些什么\n  console.log('请求被拦截了')\n  return config;\n}, function (error) {\n  // 对请求错误做些什么\n  return Promise.reject(error);\n})\nrequest.interceptors.response.use(function (response) {\n  // 对响应数据做点什么\n  console.log('响应被拦截了')\n  return response;\n}, function (error) {\n  // 对响应错误做点什么\n  return Promise.reject(error);\n})\n```\n\n## 处理 Task 任务对象\n\nwx.request\\wx.uploadFile\\wx.downloadFile\\wx.connectSocket 拥有相同的处理方法。\n\n在 config 内传入合法Task方法的 task 对象。\n\n[RequestTask](https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.html)\n\n```javascript\nrequest.downloadFile({\n  url: 'www.abc.com',\n  task: {\n    // task对象键值命名必须与官方文档Task提供的函数名一致\n    onProgressUpdate: (res, task) => {\n      // 使用自定义函数接收参数\n      yourOnProgressUpdateFun(res, task)\n    },\n    offProgressUpdate: (res, task) => {\n      yourOffProgressUpdateFunc(res, task)\n    },\n    // 如果不是on监听事件的回调函数，request传入的是task对象\n    abort: task => {\n      yourAbortFunc(task)\n    },\n  },\n});\n\nfunction yourAbortFunc(task) {\n  if (true) {\n    task.abort()\n  }\n}\n```\n\n","readmeFilename":"README.md"}