{"id":21525224,"url":"https://github.com/apijson/apijson-router","last_synced_at":"2025-04-09T23:20:31.833Z","repository":{"id":105155901,"uuid":"482509299","full_name":"APIJSON/apijson-router","owner":"APIJSON","description":"腾讯 APIJSON 的路由插件，可控地对公网暴露类 RESTful 简单接口，内部转成 APIJSON 格式请求来执行。A router plugin for Tencent APIJSON, expose undercontrolled RESTful-like HTTP API to public network, transfer to APIJSON request and execute.","archived":false,"fork":false,"pushed_at":"2025-02-16T14:51:39.000Z","size":69,"stargazers_count":14,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T01:11:11.575Z","etag":null,"topics":["apijson","http","http-server","rest","rest-api","rest-server","restful","restful-api","tencent"],"latest_commit_sha":null,"homepage":"https://github.com/Tencent/APIJSON","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/APIJSON.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":"2022-04-17T11:52:40.000Z","updated_at":"2025-02-16T14:49:50.000Z","dependencies_parsed_at":"2024-05-19T11:32:06.591Z","dependency_job_id":"4ad3e765-7e90-4ac5-8d80-a595dc63f8b8","html_url":"https://github.com/APIJSON/apijson-router","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/APIJSON%2Fapijson-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/APIJSON%2Fapijson-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/APIJSON%2Fapijson-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/APIJSON%2Fapijson-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/APIJSON","download_url":"https://codeload.github.com/APIJSON/apijson-router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126164,"owners_count":21051876,"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":["apijson","http","http-server","rest","rest-api","rest-server","restful","restful-api","tencent"],"created_at":"2024-11-24T01:33:45.154Z","updated_at":"2025-04-09T23:20:31.779Z","avatar_url":"https://github.com/APIJSON.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# apijson-router  [![](https://jitpack.io/v/APIJSON/apijson-router.svg)](https://jitpack.io/#APIJSON/apijson-router)\n腾讯 [APIJSON](https://github.com/Tencent/APIJSON) 5.1.0+ 的路由插件，可控地对公网暴露类 RESTful 简单接口，内部转成 APIJSON 格式请求来执行。\u003cbr /\u003e\nA router plugin for Tencent [APIJSON](https://github.com/Tencent/APIJSON) 5.1.0+, expose undercontrolled RESTful-like HTTP API, map to APIJSON request and execute.\u003cbr /\u003e\n\n适合在公司外的公网可控地暴露 HTTP 接口，以及方便接入 ZooKeeper, Zuul, Apollo, Nacos, SpringSecurity, Shiro, Sentinel, Hystrix 等各种使用 URL 路由的 配置、鉴权、监控、限流、熔断 等网关/框架/组件。\u003cbr /\u003e\nHTTP APIs can be exposed to public network and be under control, and can easily integrate Configuration/Authentication/Monitoring/Limitation/Isolatation projects(gateway, framework, component) using URL routes like ZooKeeper, Zuul, Apollo, Nacos, SpringSecurity, Shiro, Sentinel, Hystrix.\n\n![image](https://user-images.githubusercontent.com/5738175/166560119-c598d3c6-48b6-4f47-85fe-8f36ca332e99.png)\n\n## 添加依赖\n## Add Dependency\n\n### Maven\n#### 1. 在 pom.xml 中添加 JitPack 仓库\n#### 1. Add the JitPack repository to pom.xml\n```xml\n\t\u003crepositories\u003e\n\t\t\u003crepository\u003e\n\t\t    \u003cid\u003ejitpack.io\u003c/id\u003e\n\t\t    \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n\t\t\u003c/repository\u003e\n\t\u003c/repositories\u003e\n```\n\n![image](https://user-images.githubusercontent.com/5738175/167263399-339dad4f-2884-461e-9781-f2de6d100340.png)\n\n\u003cbr /\u003e\n\n#### 2. 在 pom.xml 中添加 apijson-router 依赖\n#### 2. Add the apijson-router dependency to pom.xml\n```xml\n\t\u003cdependency\u003e\n\t    \u003cgroupId\u003ecom.github.APIJSON\u003c/groupId\u003e\n\t    \u003cartifactId\u003eapijson-router\u003c/artifactId\u003e\n\t    \u003cversion\u003eLATEST\u003c/version\u003e\n\t\u003c/dependency\u003e\n```\n\n![image](https://user-images.githubusercontent.com/5738175/167263390-f3cc8fed-9fd5-4ee1-b8d1-e2d1a695b16c.png)\n\n\u003cbr /\u003e\n\nhttps://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Java-Server/APIJSONBoot-MultiDataSource/pom.xml\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n### Gradle\n#### 1. 在项目根目录 build.gradle 中最后添加 JitPack 仓库\n#### 1. Add the JitPack repository in your root build.gradle at the end of repositories\n```gradle\n\tallprojects {\n\t\trepositories {\n\t\t\tmaven { url 'https://jitpack.io' }\n\t\t}\n\t}\n```\n\u003cbr /\u003e\n\n#### 2. 在项目某个 module 目录(例如 `app`) build.gradle 中添加 apijson-router 依赖\n#### 2. Add the apijson-router dependency in one of your modules(such as `app`)\n```gradle\n\tdependencies {\n\t        implementation 'com.github.APIJSON:apijson-router:latest'\n\t}\n```\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n## 初始化\n## Initialization\n\n#### 1.新增一个 @RestController class DemoController extends APIJSONRouterController\n#### 1.Add a @RestController class DemoController extends APIJSONRouterController\n```java\n@RestController\n@RequestMapping(\"\")\npublic class DemoController extends APIJSONRouterController\u003cLong\u003e { \n}\n```\n![image](https://user-images.githubusercontent.com/5738175/167263296-3bfd8782-c163-4461-bbed-f264be529e76.png)\n\n\u003cbr /\u003e\n\n#### 2.在 DemoController 重写 router 方法，加上注解 @PostMapping(\"router/{method}/{tag}\")\n#### 2.Override router in DemoController, and add @PostMapping(\"router/{method}/{tag}\") for router method\n```java\n\t@PostMapping(\"router/{method}/{tag}\")\n\t@Override\n\tpublic String router(@PathVariable String method, @PathVariable String tag, @RequestParam Map\u003cString, String\u003e params, @RequestBody String request, HttpSession session) {\n\t\treturn super.router(method, tag, params, request, session);\n\t}\n```\n\n![image](https://user-images.githubusercontent.com/5738175/167263339-7c7cce6e-25bf-47b1-86a3-fc2950b8938d.png)\n\n\u003cbr /\u003e\n\n#### 3.在 DemoApplication.main 方法内，APIJSONAppication.init 后调用 APIJSONRouterApplication.init\n#### 3.In DemoApplication.main, call APIJSONRouterApplication.init after APIJSONAppication.init\n```java\n\tpublic static void main(String[] args) throws Exception {\n\t\tSpringApplication.run(DemoApplication.class, args);\n\t\tAPIJSONApplication.init();\n\t\tAPIJSONRouterApplication.init();\n\t}\n```\n\n![image](https://user-images.githubusercontent.com/5738175/167263261-25fc5a02-7980-443f-94d9-76d2b488ce61.png)\n\n\u003cbr /\u003e\n\n\n参考 [APIJSONRouterController](/src/main/java/apijson/router/APIJSONRouterController.java) 的注释及 [APIJSONBoot](https://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Java-Server/APIJSONBoot) 的 [DemoController](https://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoController.java) 和 [DemoApplication](https://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoApplication.java) \u003cbr /\u003e\n\nSee document in [APIJSONRouterController](/src/main/java/apijson/router/APIJSONRouterController.java) and [DemoController](https://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoController.java), [DemoApplication](https://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoApplication.java)  in [APIJSONBoot](https://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Java-Server/APIJSONBoot)\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n## 使用\n## Usage\n\n#### 以下步骤 1, 2 可改为直接在 APIAuto 参数注入面板点击 \\[+ 添加] 按钮，再点击弹窗内 \\[发布简单接口] 按钮来自动完成\n#### Instead of step 1 and 2, you can use APIAuto to complete them automatically: click \\[+ Add], then click \\[Release simple API]\n\n![image](https://user-images.githubusercontent.com/5738175/166562199-4d96dd16-cf25-4bd4-b574-94a3c5f32685.png)\n\n\u003cbr /\u003e\n\n### 1.在 Document 表配置请求映射\n### 1.Add mapping rule in table Document\n\n例如 \u003cbr /\u003e\nE.g. \u003cbr /\u003e\n\nname: 查询动态列表\n\nurl: /router/get/momentList  // 最后必须为 /{method}/{tag} 格式：method 必须为万能通用路由名；tag 不能为 Table 或 Table\\[] 格式\n\nrequest:\n```js\n{\n    \"Moment[].page\": 0,  // 以 . 分割路径中的 key，映射以下 \"Moment[]\": { \"page\": 0 }\n    \"Moment[].count\": 10,  // 以 . 分割路径中的 key，映射以下 \"Moment[]\": { \"count\": 10 }\n    \"format\": false  // 映射以下 \"format\": false\n}\n```\n\napijson:\n```js\n{\n    \"Moment[]\": {\n        \"page\": 0,\n        \"count\": 10,\n        \"Moment\": {\n            \"@column\": \"id,userId,date\"\n        }\n    },\n    \"format\": false\n}\n```\n\n其它字段可不填，用默认值\u003cbr /\u003e\nOther columns can use default value\u003cbr /\u003e\n\n![image](https://user-images.githubusercontent.com/5738175/166565083-1db03cde-8b59-4048-af6d-78d9efb78f7c.png)\n\n\u003cbr /\u003e\n\n### 2.在 Request 表配置校验规则\n### 2.Add validation rule in table Request\n\n如果不需要校验参数则可跳过。 \u003cbr /\u003e\nThis step can be ignored if validation is not needed. \u003cbr /\u003e\n \n和普通的 APIJSON 格式请求基本一致，只是不会自动根据符合表名的 tag 来对 structure 包装一层 \"Table\": structure \u003cbr /\u003e\nThe same as common APIJSON requests, but won't wrap structure with tag to \"Table\": structure \u003cbr /\u003e\n\n例如 \u003cbr /\u003e\nE.g. \u003cbr /\u003e\n\nmethod: GET\n\ntag: momentList\n\nstructure:\n```js\n{\n    \"MUST\": \"Moment[].page\",  // 必传 Moment[].page\n    \"REFUSE\": \"!Moment[].count,!format,!\",  // 不禁传 Moment[].count 和 format，禁传 MUST 之外的其它所有 key\n    \"TYPE\": {\n        \"format\": \"BOOLEAN\",  // format 类型必须是布尔 Boolean\n        \"Moment[].page\": \"NUMBER\",  // Moment[].page 类型必须是整数 Integer\n        \"Moment[].count\": \"NUMBER\"  // Moment[].count 类型必须是整数 Integer\n    }\n}\n```\n\n![image](https://user-images.githubusercontent.com/5738175/166563592-e8d3f09f-471a-4ae1-bee9-de78ec16fefe.png)\n\n\u003cbr /\u003e\n\n### 3.测试已配置的类 RESTful 简单接口\n### 3.Test configured RESTful-like API\n\n启动项目后用 APIAuto/Postman 等 HTTP 接口测试工具发起请求 \u003cbr /\u003e\nAfter run project and the server has started, you can use HTTP tools like APIAuto/Postman to send request \u003cbr /\u003e\n\nPOST {base_url}/router/get/{tag}  // tag 可为任意符合变量名格式的字符串\n```js\n{\n    \"showKey0\": val0,\n    \"showKey1.a1\": val1,\n    \"showKey2.a2.b2\": val2\n    ...\n}\n```\n\n例如 \u003cbr /\u003e\nE.g. \u003cbr /\u003e\n\nPOST http://localhost:8080/router/get/momentList  // 对应 Document 表配置的 url\n```js\n{\n    \"Moment[].page\": 0,\n    \"Moment[].count\": 5,\n    \"format\": false\n}\n```\n\n如果 parser.isNeedVerifyContent，则会经过 Request 表校验规则来校验， \u003cbr /\u003e\nIf parser.isNeedVerifyContent, it will be validated with the rule in table Request \u003cbr /\u003e\n\n最后内部映射为： \u003cbr /\u003e\nFinally it will be mapped to： \u003cbr /\u003e\n\n```js\n{\n    \"Moment[]\": {\n        \"page\": 0,\n        \"count\": 5,\n        \"Moment\": {\n            \"@order\": \"date-\"\n        }\n    },\n    \"format\": false\n}\n```\n\n执行完 APIJSON 格式的请求后返回对应结果 \u003cbr /\u003e\nServer will execute APIJSON request and response \u003cbr /\u003e\n\n![image](https://user-images.githubusercontent.com/5738175/166560119-c598d3c6-48b6-4f47-85fe-8f36ca332e99.png)\n\n\n\u003cbr /\u003e\n有问题可以去 Tencent/APIJSON 提 issue \u003cbr /\u003e\nhttps://github.com/Tencent/APIJSON/issues/36\n\n\u003cbr /\u003e\u003cbr /\u003e\n\n#### 点右上角 ⭐Star 支持一下，谢谢 ^_^\n#### Please ⭐Star this project ^_^\nhttps://github.com/APIJSON/apijson-router\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapijson%2Fapijson-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapijson%2Fapijson-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapijson%2Fapijson-router/lists"}