{"id":20859632,"url":"https://github.com/inlym/jshttp","last_synced_at":"2025-11-07T07:03:01.890Z","repository":{"id":57284447,"uuid":"357791566","full_name":"inlym/jshttp","owner":"inlym","description":"🏷️ 面向未来的下一代 HTTP 客户端，支持 TypeScript","archived":false,"fork":false,"pushed_at":"2021-08-24T05:57:29.000Z","size":190,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-21T07:42:13.821Z","etag":null,"topics":["http","https","miniprogram","nodejs","request","xhr","xmlhttprequest"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/inlym.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-14T06:00:59.000Z","updated_at":"2023-04-14T09:54:05.000Z","dependencies_parsed_at":"2022-09-16T22:41:47.195Z","dependency_job_id":null,"html_url":"https://github.com/inlym/jshttp","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/inlym/jshttp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fjshttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fjshttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fjshttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fjshttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inlym","download_url":"https://codeload.github.com/inlym/jshttp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fjshttp/sbom","scorecard":{"id":489056,"data":{"date":"2025-08-11","repo":{"name":"github.com/inlym/jshttp","commit":"79c457fc49dadb0aad0de3c52ad6af17e50e2f13"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"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":"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":"Code-Review","score":0,"reason":"Found 0/30 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":"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":"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":"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":"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":"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":"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":"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":"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":"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":"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":"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-19T18:34:51.074Z","repository_id":57284447,"created_at":"2025-08-19T18:34:51.074Z","updated_at":"2025-08-19T18:34:51.074Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283143295,"owners_count":26786566,"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-07T02:00:06.343Z","response_time":61,"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":["http","https","miniprogram","nodejs","request","xhr","xmlhttprequest"],"created_at":"2024-11-18T04:50:47.924Z","updated_at":"2025-11-07T07:03:01.862Z","avatar_url":"https://github.com/inlym.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jshttp\n\n![JsHttp Banner](https://img.inlym.com/4a8c7a777c9b40aeba08de4c10aaa1b4.png)\n\n![GitHub](https://img.shields.io/github/license/inlym/jshttp)\n![npm](https://img.shields.io/npm/v/jshttp)\n![npm bundle size](https://img.shields.io/bundlephobia/min/jshttp)\n![npm](https://img.shields.io/npm/dw/jshttp)\n![GitHub language count](https://img.shields.io/github/languages/count/inlym/jshttp)\n![GitHub top language](https://img.shields.io/github/languages/top/inlym/jshttp)\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/inlym/jshttp)\n![Lines of code](https://img.shields.io/tokei/lines/github/inlym/jshttp)\n![GitHub commit activity](https://img.shields.io/github/commit-activity/m/inlym/jshttp)\n![GitHub Repo stars](https://img.shields.io/github/stars/inlym/jshttp?style=social)\n\n`JsHttp` 是一个面向未来的新一代 HTTP 请求客户端，支持 TypeScript，支持在任何 `Javascript` 环境中发起 HTTP 请求（目前已支持 `Node.js`，`浏览器`，各大平台小程序，包含`微信`、`QQ`、`支付宝`、`字节跳动`等平台），在各个环境提供完全一致 `API`。\n\n## 目录\n\n- [jshttp](#jshttp)\n  - [目录](#目录)\n  - [介绍](#介绍)\n    - [背景](#背景)\n    - [特点](#特点)\n  - [安装](#安装)\n  - [使用](#使用)\n    - [发起一个请求](#发起一个请求)\n    - [更方便的调用方式](#更方便的调用方式)\n  - [配置项](#配置项)\n  - [作者](#作者)\n  - [参与](#参与)\n  - [许可证](#许可证)\n\n## 介绍\n\n### 背景\n\n在日常的开发中，发起一个 HTTP 请求是非常常见的需求，作为一个全栈开发者，笔者需要同时开发 `Node.js`，`Web`，`小程序` 等端，在各端上都有各自推荐使用的 HTTP 请求库或者官方请求方法，笔者在使用过程中的一个痛点是需要去记住各自的参数，每次使用还需要查文档，十分不方便。同时各个 HTTP 请求库都有一定的局限性，并不是完全符合笔者的需求，于是笔者就打算自己写一个可以横跨所有 `Javascript` 平台的 HTTP 请求库。\n\n另外，常用的 HTTP 请求库 `Axios` 本身已经非常成熟了，因此笔者基于 `Axios` 进行开发，拓展了 `Axios` 原生的 `adapter` 和 `interceptor` 来完成对应功能。\n\n### 特点\n\n`JsHttp` 具有以下特点：\n\n1. 支持所有的 `Javascript` 环境（也就是说，只要你在用 `Javascript` 写代码，你可以可以使用 `JsHttp` 来发起请求）。\n2. 完全兼容 `Axios` 参数，可以从 `Axios` 无缝迁移到 `JsHttp`。\n3. 内置了一些中间件，例如请求内容签名、格式转换等，进行简单配置后就可以直接使用。\n4. 全中文错误提示，更利于开发和调试。\n\n## 安装\n\n你可以使用 `npm` 来安装 `JsHttp` ，当然也可以使用其他工具（`yarn`, `cnpm` 等）安装，在你的项目目录安装即可，无需全局安装。\n\n安装命令：\n\n```sh\n$ npm install jshttp\n```\n\n## 使用\n\n如果你使用过 `Axios`，那么你几乎可以无缝迁移到 `JsHttp`，因为 `JsHttp` 提供了和 `Axios` 几乎完全一致的 `API` 和 `配置参数` 。在本节中，将告知你一些基本的使用方式。\n\n### 发起一个请求\n\n```javascript\n// 引入 `jshttp` 库\nconst jshttp = require('jshttp')\n\n// 发起一个请求\njshttp({\n  method: 'POST',\n  baseURL: 'https://debub.inlym.com',\n  url: '/request/abc/def',\n  params: {\n    id: 1,\n  },\n  data: {\n    name: 'inlym',\n    age: 29,\n  },\n}).then((res) =\u003e {\n  console.log(res.status)\n  console.log(res.headers)\n  console.log(res.data)\n})\n```\n\n### 更方便的调用方式\n\n对应一些常用的 `请求方法`，可以直接以 `jshttp[mehtod]` 的方式发起请求，例如：\n\n```javascript\njshttp\n  .get({\n    baseURL: 'https://debub.inlym.com',\n    url: '/request/abc/def',\n    // ...\n  })\n  .then((res) =\u003e {\n    // ...\n  })\n```\n\n当然对于更简单的请求，例如只有一个 `url` 地址的，可以直接使用下面这种方式：\n\n```javascript\njshttp.get('https://debub.inlym.com/request?id=1').then((res) =\u003e {\n  // ...\n})\n```\n\n## 配置项\n\n上面的使用示例列举了一些请求参数，下面例举所有的可用请求参数（同时提供了参数示例）：\n\n````javascript\n{\n  /**\n   * 请求方法\n   *\n   * 1. 默认值：`GET`\n   * 2. `jshttp` 库本身不对请求方法做出限制，部分第三方平台会对请求方法做限制，例如微信在微信小程序中只支持以下方法：\n   * OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE,CONNECT。\n   * 3. `jshttp` 库会对请求方法名称自动做大写处理，因此你可以填写 `get` 表示 `GET`。\n   */\n  method: 'GET',\n\n  /**\n   * 请求基础地址\n   *\n   * 1. 用于和 `url` 拼接成完整的地址\n   * 2. 可为空，不为空时要求以 `http://` 或 `https://` 开头\n   * 3. 配置项 `url` 以 `http://` 或 `https://` 开头时，配置项 `baseURL` 无效\n   */\n  baseURL: 'https://debug.inlym.com',\n\n  /**\n   * 请求地址\n   *\n   * 1. 可单独存在，或者和 `baseURL` 拼接合成完整请求地址\n   * 2. 和 `baseURL` 不能同时为空\n   * 3. 可以以 `http://` 或 `https://` 开头，此时配置项 `baseURL` 无效\n   * 3. 可包含查询字符串并同时使用 `params` 参数（最终处理时会自动将两者合并）\n   */\n  url: '/path/to',\n\n  /**\n   * 请求头\n   *\n   * 1. 有部分请求头被所在平台禁用，请关注各自平台禁用的请求头\n   * 2. 请求头不区分大小写，即 `'Content-Type` 和 `content-type` 不能同时存在\n   */\n  headers: {\n    'Content-Type': 'application/json',\n  },\n\n  /**\n   * 请求参数，最终以 `name=mark\u0026age=19` 的形式合并到 `url` 中\n   */\n  params: {\n    name: 'inlym',\n  },\n\n  /**\n   * 请求数据\n   *\n   * 1. 对象形式的请求数据会自动调用 `JSON.stringify` 生成字符串\n   */\n  data: {\n    nickname: 'good boy',\n    sex: 'male',\n  },\n\n  /**\n   * Mock 响应数据\n   *\n   * 不会发送真实请求，而是直接返回在 `mock` 中配置的响应数据，一般用于前端调试场景\n   */\n  mock: {\n    status: 200,\n    headers: {\n      'content-type': 'application/json',\n    },\n    data: {\n      nickname: 'good body',\n      age: 19,\n    },\n\n    /**\n     * 延迟返回时间，模拟响应返回时间，单位：毫秒（ms），可为空\n     */\n    delay: 2000,\n  },\n\n  /**\n   * 重试次数\n   *\n   * 使用 `validateStatus` 方法对响应结果进行校验，校验不通过则重试。建议配合中间件的 `ctx.retries` （当前重试次数）属性操作，当其大于 0 时，进行若干操作。\n   */\n  retry: 0,\n\n  /****************** 以下配置项一般情况下不需要额外设置，使用默认值即可 *********************/\n\n  /**\n   * 响应的数据类型\n   *\n   * 合法值：\n   * 1. `json` - 默认值\n   * 2. `arraybuffer`\n   * 3. `text`\n   * 4. `blob`\n   * 5. `document`\n   * 6. `stream`\n   */\n  responseType: 'json',\n\n  /**\n   * 响应的字符编码\n   *\n   * 仅用于 `Node.js`，一般情况下无需设置\n   *\n   * 合法值：\n   * 1. `utf8` - 默认值\n   * 2. `utf-8` - 等同于 `utf8`\n   * 3. `utf16le`\n   * 4. `latin1`\n   * 5. `base64`\n   * 6. `hex`\n   * 7. `ascii`\n   * 8. `binary`\n   * 9. `ucs2`\n   */\n  responseEncoding: 'utf8',\n\n  /**\n   * 请求超时时间\n   *\n   * 说明：\n   * 1. `0` （默认值）表示无超时时间\n   * 2. 单位：毫秒（ms）\n   */\n  timeout: 0,\n\n  /**\n   * 用户自定义中间件列表\n   *\n   * 1. 关于 `中间件` 请查看中间件章节\n   * 2. 这里配置的中间件列表仅用于本次请求\n   */\n  middleware: [],\n\n  /**\n   * 是否是正常的响应状态码，函数返回为 `false` 将直接报错\n   * @param {number} status 响应状态码\n   *\n   * 以下是默认值，正常响应状态码 200 ~ 299\n   */\n  validateStatus: function (status) {\n    return typeof status === 'number' \u0026\u0026 status \u003e= 200 \u0026\u0026 status \u003c 300\n  },\n\n  /**\n   * 请求适配器\n   *\n   * 这是 `jshttp` 能够兼容多平台的核心，判断所在平台，使用对应的适配器去承接请求，统一封装后返回。\n   *\n   * 你一般无需自定义适配器，可能用到需要自定义适配器的场景：\n   * 1. `jshttp` 暂未支持的平台\n   * 2. 更个性化的 `mock` 方案\n   */\n  adapter: function (config) {\n    // ...\n    return {\n      status: 200,\n      statusText: 'OK',\n      headers: {},\n      data: {},\n    }\n  },\n\n  /**\n   * 响应的返回内容项\n   *\n   * 合法值：\n   * 1. `status`\n   * 2. `statusText`\n   * 3. `headers`\n   * 4. `data`\n   * 5. `config`\n   * 6. `request`\n   *\n   * 支持别名，格式：\n   * ```js\n   * {\n   *   item: 'status,\n   *   alias: 'statusCode'\n   * }\n   * ```\n   */\n  responseItems: ['status', 'statusText', 'headers', 'data'],\n}\n````\n\n## 作者\n\n我是 [inlym](https://www.inlym.com) ，一个 `Javascript` 开发者。\n\n如果你有任何问题或者建议，欢迎联系我，以下是我的联系方式：\n\n- 邮箱：inlym@qq.com\n- 主页：[www.inlym.com](https://www.inlym.com)\n\n## 参与\n\n非常欢迎你能够参与这个项目的开发和维护，你可以通过以下几种方式参与到项目中：\n\n1. 提建议和需求。对于几句话就能说清楚的建议和需求，你可以直接 提一个 [New Issue](https://github.com/inlym/jshttp/issues/new) 。\n2. Fork 项目，修改代码，然后提交 Pull requests 。（提交前请检查务必通过 ESLint 检查）\n\n## 许可证\n\n本项目使用 [MIT](LICENSE) 许可证。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlym%2Fjshttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finlym%2Fjshttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlym%2Fjshttp/lists"}