{"id":22541328,"url":"https://github.com/pandaoh/js-xfetch","last_synced_at":"2026-01-20T22:37:06.674Z","repository":{"id":57698597,"uuid":"485251385","full_name":"pandaoh/js-xfetch","owner":"pandaoh","description":"JavaScript Fetch Class. Fetch 的二次封装，便捷好用。","archived":false,"fork":false,"pushed_at":"2024-01-24T02:13:29.000Z","size":61,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-20T21:13:44.719Z","etag":null,"topics":["fetch","js-fetch","js-xfetch","request","x-request","xfetch","xrequest"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/js-xfetch","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/pandaoh.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-25T06:38:17.000Z","updated_at":"2022-09-02T06:30:33.000Z","dependencies_parsed_at":"2024-10-03T12:32:14.186Z","dependency_job_id":"efe99c81-6c61-4da4-b564-4ff1f41efd1a","html_url":"https://github.com/pandaoh/js-xfetch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pandaoh/js-xfetch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandaoh%2Fjs-xfetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandaoh%2Fjs-xfetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandaoh%2Fjs-xfetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandaoh%2Fjs-xfetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pandaoh","download_url":"https://codeload.github.com/pandaoh/js-xfetch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandaoh%2Fjs-xfetch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28616997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T22:24:05.405Z","status":"ssl_error","status_checked_at":"2026-01-20T22:20:31.342Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["fetch","js-fetch","js-xfetch","request","x-request","xfetch","xrequest"],"created_at":"2024-12-07T12:15:28.993Z","updated_at":"2026-01-20T22:37:06.659Z","avatar_url":"https://github.com/pandaoh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# js-xfetch\n\n\u003e A Fetch request tool wrapper, convenient global management.\n\n\u003e Fetch 被称为下一代 Ajax 技术，浏览器原生支持，采用 Promise 方式来处理数据。是一种简洁明了的 API，比 XMLHttpRequest 更加简单易用。\n\n\u003e 但是使用不太方便，本插件对 Fetch API 进行了了一次封装，解决了 Fetch API 原生的一些痛点，增加了一些常用功能并使用类初始化方便全局管理，具体功能如下。\n\n* 浏览器原生支持\n* 参数优化(参考 Axios)\n* 自动转换请求与返回数据\n* 增加请求/响应/错误拦截功能\n* 增加超时设置\n* 增加重试/重连设置\n* 主动取消请求、取消重复请求、添加请求白名单(abortController)\n* 请求头拦截处理(Headers)\n* 日志输出，请求完成时的回调(无论是否成功) Hooks。\n* 提供实例默认配置修改方法(timeout/baseUrl...)\n\n## Install\n\n```bash\nnpm install js-xfetch -S\n```\n\n## Import\n\n```javascript\n// Es or Node\nconst {\n  XFetch,\n  XFetchContentType,\n  XFetchHttpMethod,\n  XFetchHeader,\n  XFetchRequestConfig,\n  XFetchOptions,\n  CODE_MSG\n} = require('js-xfetch');\nimport {\n  XFetch,\n  XFetchContentType,\n  XFetchHttpMethod,\n  XFetchHeader,\n  XFetchRequestConfig,\n  XFetchOptions,\n  CODE_MSG\n} from 'js-xfetch';\nimport XFetch from 'js-xfetch';\n\n// Browser\n\u003cscript src=\"xfetch.min.js\"\u003e\u003c/script\u003e\n// const {\n//   XFetch,\n//   XFetchContentType,\n//   XFetchHttpMethod,\n//   XFetchHeader,\n//   XFetchRequestConfig,\n//   XFetchOptions,\n//   CODE_MSG\n// } = xfetch;\n```\n\n## Use\n\n```javascript\n$fetch = XFetch.create({\n  baseUrl: '', // default: ''\n  timeout: 5000, // timeout default: 30000\n  cancelDuplicatedRequest: true, // Whether to cancel the duplicate request default: true\n  // default: undefined\n  retryConfig: {\n    retry: 3, // count\n    delay: 2000 // delay time\n  },\n  requestHandler: (config) =\u003e {\n    console.log('requestHandler', config);\n  },\n  responseHandler: (response) =\u003e {\n    console.log('responseHandler', response);\n  },\n  errorHandler: (error) =\u003e {\n    if (XFetch.isCancel(error)) {\n      return;\n    }\n    console.log('errorHandler', error);\n  },\n  setRequestHeaders: (config) =\u003e {\n    console.log('setRequestHeaders', config);\n    // return new Headers({});\n    return config.headers;\n  },\n  requestFinally: () =\u003e {\n    console.log('requestFinally Hooks'); // The callback when the request is completed, regardless of the result.\n  }\n});\n\n$fetch\n  .get('/test', { test: 1, v: 1 }) // params\n  .then((data) =\u003e console.log(data))\n  .catch((e) =\u003e console.log(e));\n\nXFetch.post(\n  '/test/post',\n  { test: 'data' }, // data\n  {\n    // headers: Headers,\n    // 'Content-Type': 'contentType',\n    // autoContentType: Boolean,\n    // qsStringifyOptions: { hasBrackets, hasIndex, arr2str, urlEncode }\n  },\n  true // WhiteList default: false\n);\n\nXFetch.request(\n  XFetchHttpMethod.POST,\n  '/test/post',\n  {\n    // params?: any;\n    // data?: any;\n    // headers?: XFetchHeader;\n    // autoContentType?: boolean;\n    // 'Content-Type'?: string;\n    // qsStringifyOptions?: {\n    //     arr2str?: boolean;\n    //     hasIndex?: boolean;\n    //     urlEncode?: boolean;\n    //     hasBrackets?: boolean;\n    // };\n  },\n  true // WhiteList default: false\n);\n\nXFetch.cancelRequest('reason');\nXFetch.cancelWhiteListRequest('reason');\nXFetch.qsStringify({ start: 0, count: 20, obj: { a: 1 }, arr: [1, 2, 3], str: '1' }, { hasIndex: true }); // 'start=0\u0026count=20\u0026obj[a]=1\u0026arr[0]=1\u0026arr[1]=2\u0026arr[2]=3\u0026str=1'\nXFetch.qsParse('start=0\u0026count=20\u0026x=1\u0026x=2\u0026x=3'); // { start: '0', count: '20', x: [1, 2, 3], '/': 'start=0\u0026count=20\u0026x=1\u0026x=2\u0026x=3' };\n```\n\n## API Docs\n\n[API Docs](https://github.com/pandaoh/js-xfetch/blob/main/docs/README.md)\n\n## Others\n\n* [Issue](https://github.com/pandaoh/js-xfetch/issues)\n* [Pull Request](https://github.com/pandaoh/js-xfetch/pulls)\n* [hxbpandaoh@163.com](mailto:hxbpandaoh@163.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandaoh%2Fjs-xfetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpandaoh%2Fjs-xfetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandaoh%2Fjs-xfetch/lists"}