{"id":19543608,"url":"https://github.com/nodecloud/yan-client","last_synced_at":"2025-10-07T12:04:01.557Z","repository":{"id":143867486,"uuid":"91082408","full_name":"nodecloud/yan-client","owner":"nodecloud","description":"Yan makes writing nodejs http clients easier.","archived":false,"fork":false,"pushed_at":"2018-08-22T02:15:39.000Z","size":59,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-26T17:47:29.618Z","etag":null,"topics":[],"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/nodecloud.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-05-12T10:56:44.000Z","updated_at":"2018-08-22T02:15:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b120716-fb6a-4664-b54a-77fc80a2f8a3","html_url":"https://github.com/nodecloud/yan-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nodecloud/yan-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2Fyan-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2Fyan-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2Fyan-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2Fyan-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodecloud","download_url":"https://codeload.github.com/nodecloud/yan-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodecloud%2Fyan-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278770726,"owners_count":26042828,"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-10-07T02:00:06.786Z","response_time":59,"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":[],"created_at":"2024-11-11T03:19:57.467Z","updated_at":"2025-10-07T12:04:01.552Z","avatar_url":"https://github.com/nodecloud.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yan Client\nYan Client 是一种声明式的 NodeJS Http客户端。默认基于 (request)[]。使用了 ES7 decorators 语法，更加简介，方便。\n\n## 使用\n``` \nnpm install yan-client --save\n```\n\n## 例子\n```javascript\nimport YanClient, {GetMapping, PostMapping, PutMapping, DeleteMapping, Params} from 'yan-client';\nexport default new class UserClient {\n    @GetMapping('http://example.com/users')\n    @YanClient()\n    getUsers() {}\n    \n    @GetMapping('http://example.com/users/:userId')\n    @Params('params:userId')\n    @YanClient()\n    getUser(userId) {}\n    \n    @PostMapping('http://example.com/users')\n    @YanClient()\n    createUser(user) {}\n    \n    @DeleteMapping('http://example.com/users/:userId')\n    @Params('params:userId')\n    @YanClient()\n    deleteUser(userId) {}\n    \n    @PutMapping('http://example.com/users/:userId')\n    @Params('params:userId', 'body')\n    @YanClient()\n    updateUser(userId, user) {}\n}\n```\n\n## 文档\n\n### @RequestMapping(method, url)\n\n### @***Mapping(url)\n\n用来设置请求的 URL。\n\n### @Header(key, value)\n\n用来设置请求的 header。\n\n### @Params(...params)\n\n用来确定函数的参数和请求的参数的映射关系，每个参数和函数的参数按照顺序一一对应；\n其中每个参数都是由 [prefix]:[postfix] 这样的表达式组成，postfix 可以为空，\n当 postfix 为空的时候，会替换 request 对象上某个属性。例如：\n\n```javascript\nclass Test {\n    @Params(\"body\")\n    addUser(user) {} // body: {user: {username: 'test', password: 'password'}}\n}\n```\n\n当 postfix 不为空的时候会替换 request 对象某个属性的具体值，\npostfix 支持按照路径的方式比如 (body:user.username)。例如：\n\n```javascript\nclass Test {\n    @Params(\"params:userId\", \"body:user.enable\")\n    updateUser(userId, enable) {} // body: {user: {enable: \"\"}}\n}\n```\n\n\n目前支持的 prefix 有：\n\n* endpoint\n* params\n* qs\n* headers\n* body\n\n### @ResponseBody\n\n如果有这个装饰器，返回的结果就是 response 对象的 body。如果自定义 client 没有返回 body，最后仍然会返回 response。\n\n### @ResponseHeader\n\n如果有这个装饰器，返回的是 response 对象的 header。如果自定义 client 没有返回 header，最后仍然会返回 response。\n\n### @YanClient(client)\n\n必须位于所有的装饰器之后，用来最终发送 http 请求，如果不想使用 默认的 request 库来发送请求，\n可以通过 client 参数来进行自定义。\n\n```javascript\nconst customClient = {\n    send(options) {\n        /*\n            options.url\n            options.method\n            options.body\n            options.params\n            options.headers\n            options.qs\n         */\n        \n        //full response eg {body: {}, header: {}, status: 200}\n        //if you return a body object, the @ResponseBody and @ResponseHeader will be unused.\n        return response;\n    }\n}\n\nclass Test {\n    @YanClient(customClient)\n    test() {}\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodecloud%2Fyan-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodecloud%2Fyan-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodecloud%2Fyan-client/lists"}