{"id":18855487,"url":"https://github.com/springhgui/axios-taro-adapter","last_synced_at":"2025-10-17T00:45:55.281Z","repository":{"id":47728788,"uuid":"516276124","full_name":"SpringHgui/axios-taro-adapter","owner":"SpringHgui","description":"axios adaptor for taro.request","archived":false,"fork":false,"pushed_at":"2023-01-26T07:01:24.000Z","size":20,"stargazers_count":31,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T11:05:36.161Z","etag":null,"topics":["axios","http","taro"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SpringHgui.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-21T07:49:48.000Z","updated_at":"2025-02-07T07:04:21.000Z","dependencies_parsed_at":"2023-01-26T21:25:15.745Z","dependency_job_id":null,"html_url":"https://github.com/SpringHgui/axios-taro-adapter","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringHgui%2Faxios-taro-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringHgui%2Faxios-taro-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringHgui%2Faxios-taro-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringHgui%2Faxios-taro-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpringHgui","download_url":"https://codeload.github.com/SpringHgui/axios-taro-adapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248868768,"owners_count":21174757,"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","http","taro"],"created_at":"2024-11-08T03:54:04.491Z","updated_at":"2025-10-17T00:45:50.221Z","avatar_url":"https://github.com/SpringHgui.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# axios-taro-adapter\n[![npm](https://img.shields.io/npm/v/axios-taro-adapter)](https://www.npmjs.com/package/axios-taro-adapter)\n![NPM](https://img.shields.io/npm/l/axios-taro-adapter)\n\n基于`axios`支持自定义适配器，只需要针对不同环境下的http请求api进行适配进行替换，`axios`可以使用在任意平台。  \n\n由于`axios`在其他项目中大量使用，本项目实现`Taro`框架下的适配器，可以在`Taroa`项目中完美使用原汁原味的`axios`，统一团队前端技术栈，统一http请求类库。 \n\n采用此方式对项目零侵入，开发者专注于`axios`的api即可。\n\n有用点小星星支持~\n\n# Quick start\n1. `npm i axios@0.27.2`\n2. `npm i axios-taro-adapter`\n3. create axios instance\n\n仅需2行代码，完美使用`axios`替换`Taro.request`\n\n```js\n// api.js\nimport axios from \"axios\";\nimport { TaroAdapter } from \"axios-taro-adapter\";\n\nconst API_URL = \"https://api.xxxx.com/\";\nconst instance = axios.create({\n  baseURL: API_URL,\n  timeout: 10000,\n  adapter: TaroAdapter, // add this line，添加这一行使用taroAdapter\n});\n\nexport const postData = data =\u003e {\n    return instance.post(\"/api/test\", data);\n}\n```\n例如：\n原汁原味的拦截器\n```js\n// interceptors for request\ninstance.interceptors.request.use(\n  function (config) {\n    return config;\n  },\n  function (error) {\n    return Promise.reject(error);\n  }\n);\n\n// interceptors for response\ninstance.interceptors.response.use(\n  function (response) {\n    if (response.data.code !== 0) {\n      return Promise.reject(response.data);\n    } else {\n      return response.data;\n    }\n  },\n  function (error) {\n    return Promise.reject(error.message);\n  }\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringhgui%2Faxios-taro-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspringhgui%2Faxios-taro-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringhgui%2Faxios-taro-adapter/lists"}