{"id":21606317,"url":"https://github.com/hengshanmwc/box-cat","last_synced_at":"2025-04-11T04:10:28.479Z","repository":{"id":35073453,"uuid":"198959807","full_name":"hengshanMWC/box-cat","owner":"hengshanMWC","description":"针对axios和flyio之类的二度封装,将配置文件转成方法，主要解决parmas路径痛点","archived":false,"fork":false,"pushed_at":"2023-01-06T04:56:55.000Z","size":993,"stargazers_count":16,"open_issues_count":13,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-30T16:02:15.070Z","etag":null,"topics":["axios","flyio","http"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/hengshanMWC.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":"2019-07-26T06:30:19.000Z","updated_at":"2024-12-05T09:17:27.000Z","dependencies_parsed_at":"2023-01-15T13:31:11.847Z","dependency_job_id":null,"html_url":"https://github.com/hengshanMWC/box-cat","commit_stats":null,"previous_names":["hengshanmwc/film"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hengshanMWC%2Fbox-cat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hengshanMWC%2Fbox-cat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hengshanMWC%2Fbox-cat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hengshanMWC%2Fbox-cat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hengshanMWC","download_url":"https://codeload.github.com/hengshanMWC/box-cat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339224,"owners_count":21087215,"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","flyio","http"],"created_at":"2024-11-24T20:20:39.839Z","updated_at":"2025-04-11T04:10:28.458Z","avatar_url":"https://github.com/hengshanMWC.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Features\r\nApi factory\r\n## Scene\r\n      请求数据这部分，贯穿着整个前端生涯，不知你又是怎样去管理这部分模块。接口一对一写成函数然后export出去？直接this.$fetch('userInfo/1')?前者冗余，后者碎片化不好维护。\r\n      那些业务场景简单的还好，如果像后台管理那种，动不动上百个接口，如果不用一个足够简单的结构去维护这些接口，越到后期，成本越昂贵。\r\n      所以，box-cat就是为了解决这个痛点而生，通过足够简单的结构object来维护接口，并自动生成接口函数\r\n      \r\n## Introduction\r\nbox-cat只是解决接口的集中管理。到最后调用的本体还是我们传的http请求库\r\n\r\n通过接口对象和HTTP请求库（例如axios、fly.js）进行二度封装，实现api集中管理。\r\n```js\r\n// script引入\r\n\u003cscript src=\"https://unpkg.com/box-cat/dist/boxCat.js\"\u003e\u003c/script\u003e\r\nBoxCat.createProxy\r\n```\r\n\r\n```js\r\n// a.js\r\nimport { createApis, createProxy } from 'box-cat'\r\n// server其中的key只要匹配到其中的method(不区分大小写)就会生成对应的以key为名的接口函数\r\nconst server = {\r\n  // 接口函数: 接口\r\n  postFile: 'wap/file',\r\n  deleteFile: 'wap/files/:imgId',\r\n  getUserUpFile: 'wap/file/:userId/:imgId\r\n}\r\nexport default createApis(server, axios)\r\n// createApiProxy返回一个proxy\r\n// export default createProxy(server, axios)\r\n```\r\n```js\r\n// a1.js\r\nimport http from './a.js'\r\n// 方法使用和对应的HTTP请求库一样\r\nhttp.postFile({id: 1}).then().catch()\r\n/*\r\n* 如果路径带的有param，则第一个参数是params，http请求库的参数往后顺延\r\n* 当你有多段param的时候，传的是对象\r\n*/ \r\nawait http.deleteFile(1)\r\nawait http.getUserUpFile({\r\n  userId: 1,\r\n  imgId: 10\r\n})\r\n```\r\n## method\r\n__createApi__：返回所有接口方法\r\n\r\n__createApiProxy__：返回Proxy实例，惰性生成接口方法。当判断不支持proxy时，内部会优雅降级为createApi\r\n## Options\r\n```js\r\n// createApi和createApiProxy默认参数配置\r\ncreateApis(server, response, {\r\n  methods: {\r\n    'get': ['get'],\r\n    'post': ['post'],\r\n    'put': ['put'],\r\n    'delete': ['delete'],\r\n    'options': ['options'],\r\n    'head': ['head'],\r\n    'trace': ['trace'],\r\n    'connect': ['connect'],\r\n    'patch': ['patch']\r\n  },\r\n  mergeMethods: {},\r\n  rule: ':param',\r\n  methodsRule: 'startsWith'\r\n  config: {}\r\n})\r\n```\r\n### server\r\napi的管理文件，key不区分大小写\r\n### response\r\nHTTP 请求库(axios,fly.io之类)\r\n### options\r\n##### methods\r\n自定义methods,用于匹配接口函数名\r\n例如：'post': ['ADD', 'post', 'submit']\r\n##### mergeMethods\r\n合并methods\r\n##### rule\r\nparam的匹配规则\r\n##### methodsRule\r\n默认是：startsWith\r\n匹配方法 'startsWith' | 'endsWith' | 'includes'\r\n#### config\r\n其他配置,相当于axios的config\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhengshanmwc%2Fbox-cat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhengshanmwc%2Fbox-cat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhengshanmwc%2Fbox-cat/lists"}