{"id":20521982,"url":"https://github.com/imingyu/iaxios","last_synced_at":"2025-10-14T14:09:56.767Z","repository":{"id":57270652,"uuid":"100019416","full_name":"imingyu/iaxios","owner":"imingyu","description":"使用axios库发送请求，并封装多组灵活的、高效的工具插件和配置规约","archived":false,"fork":false,"pushed_at":"2017-12-21T04:40:56.000Z","size":129,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T08:25:05.476Z","etag":null,"topics":["axios","axios-extend","axios-jsonp","iaxios","interceptor","jsonp"],"latest_commit_sha":null,"homepage":null,"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/imingyu.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}},"created_at":"2017-08-11T10:10:23.000Z","updated_at":"2018-04-22T13:52:58.000Z","dependencies_parsed_at":"2022-09-14T06:32:17.186Z","dependency_job_id":null,"html_url":"https://github.com/imingyu/iaxios","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/imingyu/iaxios","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imingyu%2Fiaxios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imingyu%2Fiaxios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imingyu%2Fiaxios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imingyu%2Fiaxios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imingyu","download_url":"https://codeload.github.com/imingyu/iaxios/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imingyu%2Fiaxios/sbom","scorecard":{"id":485555,"data":{"date":"2025-08-11","repo":{"name":"github.com/imingyu/iaxios","commit":"fa56401e3d00aafd2fa84d6861f4c04cd17291ed"},"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":"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":"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":"Code-Review","score":0,"reason":"Found 0/25 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":"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":"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":"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":"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":"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-19T17:40:10.170Z","repository_id":57270652,"created_at":"2025-08-19T17:40:10.170Z","updated_at":"2025-08-19T17:40:10.170Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275486316,"owners_count":25473620,"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-09-16T02:00:10.229Z","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":["axios","axios-extend","axios-jsonp","iaxios","interceptor","jsonp"],"created_at":"2024-11-15T22:33:31.678Z","updated_at":"2025-10-14T14:09:56.750Z","avatar_url":"https://github.com/imingyu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iaxios\n[![Build Status](https://travis-ci.org/imingyu/iaxios.svg?branch=master)](https://travis-ci.org/imingyu/iaxios)\n![image](https://img.shields.io/npm/l/iaxios.svg)\n[![image](https://img.shields.io/npm/v/iaxios.svg)](https://www.npmjs.com/package/iaxios)\n[![image](https://img.shields.io/npm/dt/iaxios.svg)](https://www.npmjs.com/package/iaxios)\n\n使用axios库发送请求，并封装多组灵活的、高效的工具插件和配置规约\n\n# 核心功能\n- 使用axios库发送网络请求\n- 使用Promise API\n- 热插拔多组插件，包括：\n    - 发送前认证用户\n    - 发送前验证参数\n    - 请求完成后convert response\n    - 可使用jsonp方式发送请求\n    - formatUrl功能\n- 可注册插件（暂未开放）\n- 取消发送请求\n\n# 待完善/添加的功能\n- 更方便的区分`request error`，`checkResult reject`，`feature reject`\n- 传给回调函数的参数丰富些\n- 向外暴露类似生命周期的钩子函数\n\n# 安装\n```bash\nnpm i iaxios -S\n```\n\n# 使用\n```javascript\n//api-index.js\nimport iaxios from 'iaxios';\niaxios.options({\n    requestConfigList: {\n        \"user.list\": {\n            url: 'http://xxx.com/user/list',\n            method: 'get',\n            auth: true,\n            jsonp: false\n        },\n        \"user.detail\": {\n            url: 'http://xxx.com/user/{id}',\n            method: 'get',\n            auth: true,\n            jsonp: false\n        }\n    },\n    features: {\n        auth: {\n            enabled: true,\n            handler: function () {\n                return !!localStorage.getItem('LoginUser');\n            },\n            onUnAuth: function () {\n                alert('您还未登录，请登录！');\n                location.href = \"/user/login\";\n            }\n        }\n    }\n});\n\n//user-api.js\nimport iaxios from 'iaxios';\nexport var getList = iaxios.createRequest('user.list');\nexport var getModel = iaxios.createRequest('user.detail');\n\n\n//page1.js（已登录）\nimport * as UserApi from 'user-api.js';\nUserApi.getList({\n    pageIndex: 1,\n    pageSize: 10\n}).then(list =\u003e {\n    render(list);\n}).catch(error =\u003e {\n    console.log(error);\n})\n\n//page2.js（未登录）\nimport * as UserApi from 'user-api.js';\n//发送前会检查登录情况，并弹出alert、跳转到登录页\nUserApi.getModel({\n    id: 1\n}).then(model =\u003e {\n    render(model);\n}).catch(error =\u003e {\n    console.log(error);\n})\n\n//page3.js（已登录）\nimport * as UserApi from 'user-api.js';\n//假定请求发送需要10s后返回结果\nvar promise = UserApi.getList({\n    pageIndex: 1,\n    pageSize: 100000\n}).then(list =\u003e {\n    render(list);\n}).catch(error =\u003e {\n    console.log(error);\n});\n\n//2s后取消发送\nsetTimeout(()=\u003e{\n    promise.cancel('传递自定义数据');\n    //执行后，promise.catch回调队列会接收到下面的数据格式：\n    [\n        {\n            data:{\n                message:'传递自定义数据'\n            },\n            stage:'cancel',\n            state:'reject'\n        }\n    ]\n})\n```\n\n# API\n## createRequest (requestName, otherOptions)\n- 创建并`返回一个函数`，这个函数用于发送请求；\n- 返回的函数API及描述：\n    - 结构：`fun(data, sendOptions)`\n    - 发送前按照优先级合并配置（`mergeOptions`）：`sendOptions`，`otherOptions`，`options.requestConfigList[requestName]`，`defaultOptions`（由高到低）\n    - `data`参数是请求要发送的数据\n        - 如果`mergeOptions.method`的值为`get`，则会将`data`传递给`axios`的`parmas`配置项\n        - 如果`mergeOptions.method`的值为`post`，则会将`data`传递给`axios`的`data`配置项\n    - `sendOptions`允许你在发送前最后一次传递配置对象\n    - 函数执行后返回一个`promise`对象\n        - 本`promise`对象保函一个`cancel`方法，调用后可取消请求的发送\n        - 请求发送取消后将会`reject`promise\n    - 函数执行后即开始`前置步骤`：检查用户认证、验证参数等功能\n        - 如果前置步骤`不通过`，直接`reject`掉`promise`，并且会将执行的结果发送给`mergeOptions.handlers.rejectConvert`进行处理，将处理结束后的数据传递给`reject`函数；\n        - 如果前置步骤`通过`，则会执行发送请求\n    - 发送请求前还会执行`mergeOptions.handlers.getUrl`函数，获取请求的url；如果不配置此项，则会从`mergeOptions.axios.url`读取\n    - 请求发送成功后，执行`mergeOptions.handlers.checkResult`函数判断请求结果\n        - 如果`mergeOptions.handlers.checkResult()==true || mergeOptions.handlers.checkResult().then`后调用`mergeOptions.handlers.resolveConvert`处理请求成功的`response`对象，`mergeOptions.handlers.resolveConvert`执行后，`resolve`掉`promise`，并将处理结果传递给`resolve`函数\n        - 如果`mergeOptions.handlers.checkResult()==false || mergeOptions.handlers.checkResult().catch`后调用`mergeOptions.handlers.rejectConvert`处理请求成功的`response`对象，`mergeOptions.handlers.rejectConvert`执行后，`reject`掉`promise`，并将处理结果传递给`reject`函数\n    - 请求发送失败，执行`mergeOptions.handlers.rejectConvert`，后续步骤类似\n\n## setOptions (options)\n- 设置当前`iaxios`实例的配置对象\n\n## create (options)\n- 创建一个`iaxios`实例，并传递配置对象\n- 不同实例共享`iaxios`的`defaultOptions`，但使用实例方法`setOptions`后，设置的是本身的配置\n\n\n## iaxios实例方法\n- #createRequest\n- #setOptions\n\n# Options\n```javascript\n//options描述及默认配置\n{\n    requestConfigList: {}, //request配置元信息集合\n    axios: {\n        //axios配置\n        method: 'get',\n        paramsSerializer: util.paramsSerializer,\n        headers: {\n            common: {\n                'Content-Type': 'application/json'\n            },\n            post: {\n                'Content-Type': 'application/x-www-form-urlencoded'\n            }\n        },\n        transformRequest: [function (data, headers) {\n            return util.stringifyData(data);\n        }]\n    },\n    validators: {}, //验证器列表\n    features: { //启用iaxios的哪些功能？\n        auth: {\n            enabled: false\n        },\n        formatUrl: {\n            enabled: true,\n            removeFormatedItem: true /*\n            格式化后，是否移除已经用到的格式化项\n            支持4中值：\n            true:移除所有\n            false:保留所有\n            ['item1','item2']:移除'item1'和'item2'\n            {item1:true,item2:false}:移除'item1',保留'item2'\n             */\n        },//格式化url\n        jsonp: {\n            enabled: false,\n            callback: 'callback',\n            link: null // 怎样连接params和data？\n        }, //接口是否以jsonp方式发送\n        validator: {\n            enabled: false\n        }//启用验证器，调用iaxios.createRequest()返回的方法时，先取request配置中的验证器去验证参数，验证通过才会执行下面的逻辑\n    },\n    handlers: {\n        //获取请求的真实url\n        getUrl(requestConfig) {\n            return requestConfig.url;\n        },\n        //检查请求返回的结果，成功请resolve，失败请reject\n        checkResult(res, requestConfig) {\n            return res \u0026\u0026 res.data ? true : false;\n        },\n        //格式化请求成功的数据\n        resolveConvert(res, requestConfig) {\n            return res.data;\n        },\n        //格式化请求失败的数据\n        rejectConvert(rejectDataMap, requestConfig) {\n            return rejectDataMap;\n        }\n    }\n};\n```\n\n\n# 更新日志\n## v0.2.1\n- 添加`formatUrl`支持\n\n## v0.2.0\n- 添加`jsonp`支持\n\n## v0.1.8\n- 在`rejectConvert`，`resolveConvert`回调中新增参数`computeOptions`——计算后的`axios`请求配置对象\n\n## v0.1.7\n- 处理一些已知的BUG\n\n## v0.1.5\n- 重构`options`的获取机制，在执行`request`发送时，`options`会做一次合并，后续所有配置均在此合并后的对象上读取，合并规则：\n```javascript\nvar mergeOptions = util.extend(true, {}, iaxios.options, iaxios.options.requestConfigList[requestName], otherOptions, sendOptions);\n```\n- 删除`getOptionItem`方法\n- 处理一些已知的BUG\n\n## v0.1.3\n- 为`handlers`的相关`convert`方法添加第二个参数`requestConfig`\n- 更新文档：添加options注释\n- 处理一些已知的BUG\n\n\n## v0.1.0\n- 核心功能实现","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimingyu%2Fiaxios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimingyu%2Fiaxios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimingyu%2Fiaxios/lists"}