{"id":21716706,"url":"https://github.com/postor/as-json-service","last_synced_at":"2026-05-08T13:10:29.383Z","repository":{"id":230266458,"uuid":"126759016","full_name":"postor/as-json-service","owner":"postor","description":"create http json service from a Class","archived":false,"fork":false,"pushed_at":"2018-03-27T08:31:15.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-26T04:17:58.659Z","etag":null,"topics":["json-service","microservice"],"latest_commit_sha":null,"homepage":null,"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/postor.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}},"created_at":"2018-03-26T01:50:18.000Z","updated_at":"2024-02-28T18:53:48.000Z","dependencies_parsed_at":"2024-03-28T19:17:28.059Z","dependency_job_id":"31006c0b-2381-4044-a292-146fbacfaf60","html_url":"https://github.com/postor/as-json-service","commit_stats":null,"previous_names":["postor/as-json-service"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postor%2Fas-json-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postor%2Fas-json-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postor%2Fas-json-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postor%2Fas-json-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postor","download_url":"https://codeload.github.com/postor/as-json-service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244679638,"owners_count":20492450,"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":["json-service","microservice"],"created_at":"2024-11-26T01:12:50.577Z","updated_at":"2026-05-08T13:10:24.347Z","avatar_url":"https://github.com/postor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# as-json-service\n\ncreate http json api service in one command | 一键启动基于http的json接口服务\n\n## usage | 使用方法\n\ninstall globally | 全局安装\n\n```\nnpm i as-json-service -g\n```\n\ntest.js\n\n```\nmodule.exports = {\n  sayHi: async (params)=\u003e{\n    return {\n      message: `hello ${params.name}`\n    }\n  }\n}\n```\n\nrun command | 运行命令\n\n```\nas-json-service --file=test.js\n```\n\ntest command | 测试命令结果\n\n```\ncurl http://localhost:3000/say-hi?name=world\n```\n\nresult | 结果\n\n```\n{\"message\":\"hello world\"}\n```\n\n## micro service | 微服务\n\nusually a project starts from a small one, if you start with micro services, you may wast a lot of time on the framework, if not it may end up grow too large to maintain. so I want build a project witch will easily convert into micro services, so an agent that able to handle it from both network and local module is more convenient, the low level behaver is configed in a file so you can one code and different structures in different enviroment, for example develop with local module and test/publish with network\n\n通常一个项目开始的时候很小，如果你开始就使用微服务，那么你会浪费很多时间在框架搭建上，如果不用微服务，又很可能项目变得太大而无法维护。所以我希望可以构建一个能够轻松转换到微服务模式的项目，那么如果有一个代理能够从本地模块和网络两个途径调用的模块会是非常便利的，底层的行为可以通过一个额外的配置文件来配置，这样你就可以使用一套代码在不同环境上拥有不同的架构了，比如开发的时候使用本地模块，而测试和产线使用网络（微服务架构）\n\ninstall locally | 本地安装\n\n```\nnpm i as-json-service --save\n```\n\ntest2.js where you will need to use logic from test.js | test2.js 会使用到 test.js 的逻辑\n\n```\nconst { join } = require('path')\n\n// old way\n// const c1 = require('./test.js')\n\n// new way\nconst { getAgent } = require('as-json-service')\nconst c1 = getAgent(join(__dirname, 'test.js'))\n\nmodule.exports = {\n  sayHi: async (params)=\u003e{\n    try {\n      const fromC1 = await c1.sayHi(params)\n      return {\n        message: `${fromC1.message}, welcome!`,\n      }  \n    }catch(error){\n      return {\n        error,\n      }\n    }    \n  }\n}\n\n```\n\ngenerate config | 生成配置\n\n```\nas-json-service-config --file=test.js --baseUrl=http://localhost:3000\n```\n\nserve test.js | 启动test.js的服务\n\n```\nas-json-service --file=test.js\n```\n\nserve test2.js | 启动test2.js\n\n```\nas-json-service --file=test2.js --port=3001\n```\n\ntest command | 测试test2服务\n\n```\ncurl http://localhost:3001/say-hi?name=postor\n```\n\nresult | 结果\n\n```\n{\"message\":\"hello world, welcome!\"}\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostor%2Fas-json-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostor%2Fas-json-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostor%2Fas-json-service/lists"}