{"id":16978422,"url":"https://github.com/rainmango/axios-mapper","last_synced_at":"2025-03-17T08:38:09.349Z","repository":{"id":53693132,"uuid":"320784897","full_name":"RainManGO/axios-mapper","owner":"RainManGO","description":"🚀🚀make ts project easy to requset transform model","archived":false,"fork":false,"pushed_at":"2022-10-25T00:54:13.000Z","size":308,"stargazers_count":41,"open_issues_count":4,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-27T21:49:40.817Z","etag":null,"topics":["axios","axios-mapper","axios-model","axios-plugin","ts","ts-transform-model"],"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/RainManGO.png","metadata":{"files":{"readme":"README-ZH.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":"2020-12-12T08:36:28.000Z","updated_at":"2023-08-18T02:14:46.000Z","dependencies_parsed_at":"2023-01-20T11:15:20.825Z","dependency_job_id":null,"html_url":"https://github.com/RainManGO/axios-mapper","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RainManGO%2Faxios-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RainManGO%2Faxios-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RainManGO%2Faxios-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RainManGO%2Faxios-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RainManGO","download_url":"https://codeload.github.com/RainManGO/axios-mapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243853681,"owners_count":20358461,"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","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-mapper","axios-model","axios-plugin","ts","ts-transform-model"],"created_at":"2024-10-14T01:43:25.584Z","updated_at":"2025-03-17T08:38:08.786Z","avatar_url":"https://github.com/RainManGO.png","language":"TypeScript","readme":"Language: [English](README.md) | [中文简体](README-ZH.md)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"192\" src=\"https://img-blog.csdnimg.cn/20201214142404283.png\" alt=\"axios mapper\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/axios-mapper\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/axios-mapper?color=blue\" alt=\"npm\"\u003e\n  \u003c/a\u003e\n   \u003ca href=\"https://www.npmjs.com/package/axios-mapper\"\u003e\n    \u003cimg src=\"https://img.shields.io/node/v/axios-mapper\" alt=\"npm\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/axios-mapper\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dw/axios-mapper\" alt=\"npm\"\u003e\n  \u003c/a\u003e\n   \u003ca href=\"https://www.npmjs.com/package/axios-mapper\"\u003e\n    \u003cimg src=\"https://img.shields.io/bundlephobia/minzip/axios-mapper\" alt=\"npm\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/RainManGO/axios-mapper/blob/main/LICENSE\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/l/axios-mapper\" alt=\"License\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\n\u003e在移动端和后台进行数据操作的时候，我们往往会将网络请求抽象一个model层，便于维护和开发使用。\n\n\n前端用TS做项目，抽象model层是非常有必要。\n\n\n[axios-mapper](https://github.com/RainManGO/axios-mapper)是用来解决这个问题，让请求直接返回model。而且优化请求，防止过快点击重复请求。\n\n注意点：axios-mapper 的初衷是为了解决模型转换的问题，是axios 上层的简单封装，如果上传文件或者一些特殊处理可以直接使用axios \n\n## 功能\n- [x] 更简单的axios请求返回自动转成model\n- [x] 自定义间隔时间，防止重复快速点击\n\n\n## 安装\n\n```shell\n  npm install  axios-mapper\n```\nor\n\n```shell\n  yarn add axios-mapper\n```\n\n## 简单使用\n1、基础配置\n```js\n import HttpClient,{HttpClientConfig} from \"../src/index\";\n const config:HttpClientConfig = {\n    baseURL:'http://www.httpbin.org',\n    headers:{\n        token:'your token'\n    }    \n }\nconst https = new HttpClient(config)\nexport default https\n```\n\n2 、自动化产生model\n\nvscode extension : [json2ts](https://marketplace.visualstudio.com/items?itemName=GregorBiswanger.json2ts)\nweb：[http://json2ts.com](http://json2ts.com)\n\n```javascript\n// {\n//     \"slideshow\": {\n//       \"author\": \"Yours Truly\",\n//       \"date\": \"date of publication\",\n//       \"slides\": [\n//         {\n//           \"title\": \"Wake up to WonderWidgets!\",\n//           \"type\": \"all\"\n//         },\n//         {\n//           \"items\": [\n//             \"Why \u003cem\u003eWonderWidgets\u003c/em\u003e are great\",\n//             \"Who \u003cem\u003ebuys\u003c/em\u003e WonderWidgets\"\n//           ],\n//           \"title\": \"Overview\",\n//           \"type\": \"all\"\n//         }\n//       ],\n//       \"title\": \"Sample Slide Show\"\n//     }\n//   }\n\nexport interface Slide {\n\ttitle: string;\n\ttype: string;\n}\n\nexport interface Slideshow {\n\tauthor: string;\n\tdate: string;\n\tslides: Slide[];\n\ttitle: string;\n}\n\nexport interface RootObject {\n\tslideshow: Slideshow;\n}\n```\n\n3、请求时获得转换\n\n```javascript\nimport  https  from \"./http\";\nimport { RootObject } from \"./model\";\n\nhttps.request\u003cRootObject\u003e('/json').then((res)=\u003e{\n    console.log(res?.slideshow);\n})\n```\n\n## 全部配置\n\n配置基于AxiosRequestConfig类，扩展新增默认参数和间隔时间\n\n```javascript\nexport interface HttpClientConfig extends AxiosRequestConfig {\n //所有请求可以带默认参数\n  defaultParams?: RequestParams,\n  //click interval (点击间隔时间)\n  clickInterval?:number\n}\n```\n\n\n\n## 依赖\n\n - axios\n - qs\n\n## 脚本\n\nuse  [tsdx](https://github.com/formium/tsdx)  to publish\n\n## License\naxios-mapper: Axios is open-sourced software licensed under the [MIT license](./LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frainmango%2Faxios-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frainmango%2Faxios-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frainmango%2Faxios-mapper/lists"}