{"id":17571271,"url":"https://github.com/netpi/request3","last_synced_at":"2025-03-29T14:45:24.257Z","repository":{"id":83303258,"uuid":"94468394","full_name":"netpi/request3","owner":"netpi","description":null,"archived":false,"fork":false,"pushed_at":"2017-06-19T07:39:42.000Z","size":180,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"dev","last_synced_at":"2025-02-04T15:48:31.860Z","etag":null,"topics":[],"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/netpi.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":"2017-06-15T18:37:17.000Z","updated_at":"2017-06-15T18:37:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"8b501b8c-9bc8-468e-8a3b-dbd16da44ca4","html_url":"https://github.com/netpi/request3","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netpi%2Frequest3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netpi%2Frequest3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netpi%2Frequest3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netpi%2Frequest3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netpi","download_url":"https://codeload.github.com/netpi/request3/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246200296,"owners_count":20739563,"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":[],"created_at":"2024-10-21T18:23:21.729Z","updated_at":"2025-03-29T14:45:24.232Z","avatar_url":"https://github.com/netpi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Request\n---\n\u003e send request with ajax jsonp and native request\n\n### 基本思路图\n\n\u003cimage src=\"https://olxvlcccu.qnssl.com/blog/g4kdu.jpg?imageslim\" width=300/\u003e\n\n### 目录结构\n\n``` sh\n.\n├── LICENSE\n├── lib # 最后打包生成 (es5)\n│   ├── request3.min.js # 30KB\n│   └── request3.js.map\n├── package.json\n├── readme.md\n├── src # 源文件 (es6)\n│   ├── adapter\n│   │   ├── ajax.js # ajax 通道 \n│   │   ├── jsRouter.js # native 通道 (js 桥接)\n│   │   └── jsonp.js # jsonp 通道\n│   ├── core\n│   │   ├── InterceptorManager.js # 拦截器 AOP的实现\n│   │   ├── Request.js # Api 核心\n│   │   ├── cache.js # 缓存\n│   │   └── dispatchRequest.js # 请求通道分发\n│   ├── default.js # 默认配置\n│   ├── request3.js # Api 入口\n│   └── utils\n│       └── store.js\n├── test\n├── webpack.config.js\n└── yarn.lock\n\n```\n\n### TODO\n\n最新TODO (2017.6.17 )\n\n- [x] 重构了架构\n  - [x] 完成 拦截器核心代码 =\u003e [InterceptorManager.js](https://github.com/netpi/request3/blob/dev/src/core/InterceptorManager.js)\n  - [x] 利用Promise 实现 AOP 拦截, 实现了方法可注册, 从而将 `request` `response` 独立出来 =\u003e [[Request.js#L18-L34](https://github.com/netpi/request3/blob/dev/src/core/Request.js#L18-L34)]\n  - [x] 完成  `dispatchRequest.js` 实现请求通道分发\n  - [x] 为request3动态注册 `['delete', 'get', 'head', 'options', 'post', 'put', 'patch']`方法 来支持 `request.get` `request.post` 方式请求, 并且保证通道对web端透明 =\u003e [[Request.js#L38-L40](https://github.com/netpi/request3/blob/dev/src/core/Request.js#L38-L40)]\n  - [x] 实现了开发环境热更新, 提高开发效率\n  - [x] 完善了webpack 环境配置, 支持生产环境 代码压缩 source-map 等\n\n本次重构的优点与特点\n\n* 利用promise 实现了AOP拦截 , 可以方便的在 chain 中注册方法 来实现`request` `response`的拦截, 利用拦截器实现了文件的分工分离.\n* 将API独立抽离出来, 动态为request3 注册`['delete', 'get', 'head', 'options', 'post', 'put', 'patch']` 等HTTP方法,支持 `request3.get()` 形式 . 并且实现了 `API` `转发器` `请求通道`的分离\n* 利用AOP 将缓存注册在 `request` 请求前后, 灵活控制缓存 \n* 完善了工程化流程 : \n  * 清晰了开发架构, \n  * 实现了开发环境的 `热更新`  \n  * 生产环境的  `代码压缩` `source-map` 等\n\n---\n\u003e 目前完成以下这些 基本用时6个小时左右吧 (已懵逼)! (2017.6.16 凌晨4点)\n\n- [x] 基础开发环境搭建\n- [x] 设计完成 Reuest 类基本结构\n- [x] 封装原生ajax 发送请求\n- [x] 封装jsonp 发送请求\n- [x] 用js调起 native 方法 \n- [x] 添加全局参数 (局部请求参数优先)\n- [x] 抽象出统一请求 (方便加缓存)\n- [x] 设计并实现缓存系统 (基于 store.js 库)\n- [x] 添加 example 并调试\n- [ ] 添加 e2e 测试用例\n- [ ] request 支持 promise \n- [ ] 完善错误处理机制\n- [ ] 代码目录结构优化\n- [ ] 封装成完整可发布的npm库\n- [ ] webpack环境配置增强(如代码压缩/热更新/eslint等)\n- [x] 修复babel编译bug\n等等 ...\n\n### 使用 \n\n\u003e 演示 : https://request3.now.sh/\n\n```js\n\nvar root = 'https://jsonplaceholder.typicode.com';\n\nrequest3.get({\n  url: root + '/posts/2',\n  cache: true, // 不填继承全局\n  expire: 3000, // 单个请求缓存过期时间\n  adapter:'ajax' // ajax json native ; default 'ajax'\n}).then(function(resp){\n  console.log(resp)\n})\n\n\n```\n\n主要参考资料 :\n\nhttps://github.com/marcuswestin/store.js\n\nhttp://www.jianshu.com/p/9b52aaff4f5a\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetpi%2Frequest3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetpi%2Frequest3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetpi%2Frequest3/lists"}