{"id":33001915,"url":"https://github.com/afishhhhh/weapp.request","last_synced_at":"2025-11-16T07:00:49.216Z","repository":{"id":143927803,"uuid":"171494067","full_name":"afishhhhh/weapp.request","owner":"afishhhhh","description":"为微信小程序提供的网络请求组件，是 wx.request 的扩展，基于 Promise API，添加缓存控制","archived":false,"fork":false,"pushed_at":"2019-07-17T04:01:34.000Z","size":31,"stargazers_count":31,"open_issues_count":1,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-30T19:33:17.372Z","etag":null,"topics":["javascript","miniprogram","weapp","wechat","wxapp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/afishhhhh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-02-19T15:02:44.000Z","updated_at":"2025-02-26T07:27:35.000Z","dependencies_parsed_at":"2024-01-06T23:55:30.456Z","dependency_job_id":"360f30f6-3653-42b8-ac11-8d1decd7ef80","html_url":"https://github.com/afishhhhh/weapp.request","commit_stats":null,"previous_names":["afishhhhh/mp-request"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/afishhhhh/weapp.request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afishhhhh%2Fweapp.request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afishhhhh%2Fweapp.request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afishhhhh%2Fweapp.request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afishhhhh%2Fweapp.request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afishhhhh","download_url":"https://codeload.github.com/afishhhhh/weapp.request/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afishhhhh%2Fweapp.request/sbom","scorecard":{"id":169798,"data":{"date":"2025-08-11","repo":{"name":"github.com/afishhhhh/weapp.request","commit":"4e06bf962e8092f8391ef4527b1dc0d034810175"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/24 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-16T16:06:47.599Z","repository_id":143927803,"created_at":"2025-08-16T16:06:47.599Z","updated_at":"2025-08-16T16:06:47.599Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284672648,"owners_count":27044736,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-16T02:00:05.974Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","miniprogram","weapp","wechat","wxapp"],"created_at":"2025-11-13T14:00:24.545Z","updated_at":"2025-11-16T07:00:49.204Z","avatar_url":"https://github.com/afishhhhh.png","language":"JavaScript","funding_links":[],"categories":["组件"],"sub_categories":[],"readme":"# weapp.request\n\n一个为微信小程序提供的，基于 wx.request 扩展的网络请求组件库。\n\n### Features\n\n1. Promise API\n2. 缓存控制\n3. 请求/响应拦截器\n\n### Install\n\n##### 推荐使用 npm 安装\n\n```\nnpm install weapp.request -S\n```\n\n### Quick Start\n\n##### 引入 weapp.request\n\n``` javascript\nconst request = require('weapp.request')\n```\n\n1. 发送一个 GET 请求\n\n   ``` javascript\n   request('https://api.github.com').then(onFulfilled).catch(onRejected)\n   ```\n\n   因为所有的 `request` 调用都会返回一个 `Promise`，所以可以使用 `then` 对请求结果进行进一步处理，用 `catch` 来捕获内部抛出的错误。\n\n2. 发送一个 GET 请求，并写入缓存\n\n   ``` javascript\n   request('https://api.github.com', {}, {\n     cache: true\n   })\n   ```\n\n\n3. 发送一个 POST 请求\n\n   ``` javascript\n   request.post('https://api.github.com', {\n     user: 'afishhhhh'\n   })\n   ```\n\n   除了 GET 请求以外，所有其他的 method 都要以 `request.method` 的形式进行调用。\n\n   根据[微信官方文档](https://developers.weixin.qq.com/miniprogram/dev/api/wx.request.html#data-%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E)的说明，以上 POST 方法且 `Content-Type` 默认为 `application/json`，会对数据进行 JSON 序列化。\n\n   如果需要以 query string 的形式将数据发送给服务器，可以采取以下调用方法，不需要显示的将 `Content-Type` 写为 `application/x-www-form-urlencoded`：\n\n   ``` javascript\n   request.post('https://api.github.com', {\n     form: {\n       user: 'afishhhhh'\n     }\n   })\n   ```\n\n4. 全局配置\n\n   | 配置选项            | 类型                   | 说明                                       | 必填   | 默认值                                 |\n   | :-------------- | -------------------- | ---------------------------------------- | ---- | ----------------------------------- |\n   | baseUrl         | `String/Undefined`   | 基础请求路径                                   | 否    |                                     |\n   | cacheMaxAge     | `Number/Undefined`   | 缓存有效期，时间单位为秒                             | 否    | 1800                                |\n   | validStatusCode | `Function/Undefined` | status code 合法区间，该函数接受一个参数，并返回一个 `Boolean` | 否    | `code =\u003e code \u003e= 200 \u0026\u0026 code \u003c 300` |\n\n   ``` javascript\n   request.config({\n     baseUrl: 'https://api.github.com'\n   })\n   ```\n\n5. 请求/响应拦截器\n\n   ```\n   // 添加请求拦截器\n   request.interceptors.req.use(function (request) {\n     request.header['X-Tag'] = 'weapp.request'\n     // return request 可以显式地返回一个 request，如果没有 return，则默认返回当前 request\n   })\n   ```\n   响应拦截器同理。\n   ```\n   // 移除请求拦截器\n   request.interceptors.req.remove()\n   ```\n\n### APIs\n\n#####  `request(url, params, options)`\n\n发起一个 GET 请求。\n\n**`params`**：请求参数，类型为 `Object`，非必填。\n\n**`options`**：配置项，类型为 `Object`，非必填，可以有以下属性值：\n\n| 属性           | 类型                  | 必填   | 默认值         | 说明                                       |\n| ------------ | ------------------- | ---- | ----------- | ---------------------------------------- |\n| cache        | `Boolean/Undefined` | 否    | `undefined` | `undefined` 表示从服务器获取最新数据，不写入缓存；`true` 表示优先从缓存中获取数据，如果缓存中不存在该数据或者缓存已失效，则从服务器获取数据，并写入缓存；`false` 表示优先从服务器获取数据，并将数据写入缓存 |\n| header       |                     |      |             | 同微信官方文档                                  |\n| dataType     |                     |      |             | 同微信官方文档                                  |\n| responseType |                     |      |             | 同微信官方文档                                  |\n\n\n\n##### `request.method(url, params, options)`\n\n`method` 可以是 `get`，`post` 等等。\n\n\n\n##### `request.config(options)`\n\n**`options`**：配置项，类型为 `Object`。\n\n### License\n\nThis code is distributed under the terms and conditions of the [MIT license](LICENSE).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafishhhhh%2Fweapp.request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafishhhhh%2Fweapp.request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafishhhhh%2Fweapp.request/lists"}