11# apijson-router [ ![ ] ( https://jitpack.io/v/APIJSON/apijson-router.svg )] ( https://jitpack.io/#APIJSON/apijson-router )
2- 腾讯 [ APIJSON] ( https://github.com/Tencent/APIJSON ) 5.0.5+ 的路由插件,对外暴露类 RESTful 简单接口,内部转成 APIJSON 格式请求来执行。<br />
3- A router plugin for Tencent [ APIJSON] ( https://github.com/Tencent/APIJSON ) 5.0.5+, expose RESTful-like HTTP API, transfer to APIJSON request and execute.
2+ 腾讯 [ APIJSON] ( https://github.com/Tencent/APIJSON ) 5.1.0+ 的路由插件,对外暴露类 RESTful 简单接口,内部转成 APIJSON 格式请求来执行。<br />
3+ A router plugin for Tencent [ APIJSON] ( https://github.com/Tencent/APIJSON ) 5.1.0+, expose RESTful-like HTTP API, map to APIJSON request and execute.
4+
5+ ![ image] ( https://user-images.githubusercontent.com/5738175/166560119-c598d3c6-48b6-4f47-85fe-8f36ca332e99.png )
46
57## 添加依赖
68## Add Dependency
@@ -52,7 +54,6 @@ A router plugin for Tencent [APIJSON](https://github.com/Tencent/APIJSON) 5.0.5+
5254 }
5355```
5456
55- <br />
5657<br />
5758<br />
5859
@@ -79,76 +80,97 @@ A router plugin for Tencent [APIJSON](https://github.com/Tencent/APIJSON) 5.0.5+
7980
8081See 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 )
8182
82- <br />
8383<br />
8484<br />
8585
8686## 使用
8787## Usage
88- ### 1.配置 Document 请求映射
88+
89+ #### 以下步骤 1, 2 可改为直接在 APIAuto 参数注入面板点击 \[ + 添加] 按钮,再点击弹窗内 \[ 发布简单接口] 按钮来自动完成
90+ #### Instead of step 1 and 2, you can use APIAuto to complete them automatically: Click \[ + Add] , then Click \[ Release simple API]
91+
92+ ![ image] ( https://user-images.githubusercontent.com/5738175/166562199-4d96dd16-cf25-4bd4-b574-94a3c5f32685.png )
93+
94+ <br />
95+
96+ ### 1.在 Document 表配置请求映射
97+ ### 1.Add mapping rule in table Document
8998
9099例如 <br />
100+ Eg <br />
91101
92102name: 查询动态列表
93103
94- url: /get/moments // 必须以 APIJSON 的万能通用 API 之一的路由开头,例如 /get/, /post/ 等
104+ url: /router/ get/momentList // 最后必须为 /{method}/{tag} 格式:method 必须为万能通用路由名;tag 不能为 Table 或 Table \[ ] 格式
95105
96106request:
97107``` js
98108{
99- " format " : true , // 替换以下 "format ": false
100- " Moment[].count" : 3 , // 以 . 分割路径中的 key,替换以下 "Moment[]": { "count": 3 }
101- " Moment[].page " : 1 // 以 . 分割路径中的 key,替换以下 "Moment[] ": { "page": 1 }
109+ " Moment[].page " : 0 , // 以 . 分割路径中的 key,映射以下 "Moment[] ": { "page": 0 }
110+ " Moment[].count" : 10 , // 以 . 分割路径中的 key,映射以下 "Moment[]": { "count": 10 }
111+ " format " : false // 映射以下 "format ": false
102112}
103113```
104114
105115apijson:
106116``` js
107117{
108- " foramt" : false ,
109118 " Moment[]" : {
110- " Moment" : {
111- " @order" : " date-"
112- },
113119 " page" : 0 ,
114- " count" : 5
115- }
120+ " count" : 10 ,
121+ " Moment" : {
122+ " @column" : " id,userId,date"
123+ }
124+ },
125+ " format" : false
116126}
117127```
118128
119- 其它字段可不填,用默认值。
129+ 其它字段可不填,用默认值<br />
130+ Other columns can use default value<br />
120131
121- < br />< br />
132+ ![ image ] ( https://user-images.githubusercontent.com/5738175/166565083-1db03cde-8b59-4048-af6d-78d9efb78f7c.png )
122133
123- ### 2.配置 Request 表校验规则
124- 如果不需要校验参数则可跳过。 <br />
134+ <br />
135+
136+ ### 2.在 Request 表配置校验规则
137+ ### 2.Add validation rule in table Request
125138
126- 和普通的 APIJSON 格式请求基本一致,只是不会自动根据符合表名的 tag 来对 structure 包装一层 "Table": structure
139+ 如果不需要校验参数则可跳过。 <br />
140+ This step can be ignored if validation is not needed. <br />
141+
142+ 和普通的 APIJSON 格式请求基本一致,只是不会自动根据符合表名的 tag 来对 structure 包装一层 "Table": structure <br />
143+ The same as common APIJSON requests, but won't wrap structure with tag to "Table": structure <br />
127144
128145例如 <br />
146+ Eg <br />
129147
130148method: GET
131149
132- tag: moments
150+ tag: momentList
133151
134152structure:
135153``` js
136154{
137- " MUST" : " foramt,Moment[].count,Moment[].page" ,
155+ " MUST" : " Moment[].page" , // 必传 Moment[].page
156+ " REFUSE" : " !Moment[].count,!format,!" , // 不禁传 Moment[].count 和 format,禁传 MUST 之外的其它所有 key
138157 " TYPE" : {
139- " foramt" : " BOOLEAN" ,
140- " Moment[].page" : " NUMBER" ,
141- " Moment[].count" : " NUMBER"
142- },
143- " REFUSE" : " !"
158+ " format" : " BOOLEAN" , // format 类型必须是布尔 Boolean
159+ " Moment[].page" : " NUMBER" , // Moment[].page 类型必须是整数 Integer
160+ " Moment[].count" : " NUMBER" // Moment[].count 类型必须是整数 Integer
161+ }
144162}
145163```
146164
147- <br /><br />
165+ ![ image] ( https://user-images.githubusercontent.com/5738175/166563592-e8d3f09f-471a-4ae1-bee9-de78ec16fefe.png )
166+
167+ <br />
148168
149- ### 3.测试类 RESTful API
169+ ### 3.测试已配置的类 RESTful 简单接口
170+ ### 3.Test configured RESTful-like API
150171
151172启动项目后用 APIAuto/Postman 等 HTTP 接口测试工具发起请求 <br />
173+ After run project and the server has started, you can use HTTP tools like APIAuto/Postman to send request <br />
152174
153175POST {base_url}/router/get/{tag} // tag 可为任意符合变量名格式的字符串
154176``` js
@@ -161,39 +183,41 @@ POST {base_url}/router/get/{tag} // tag 可为任意符合变量名格式的字
161183```
162184
163185例如 <br />
186+ Eg <br />
164187
165- POST http://localhost:8080/router/get/moments // Document 表配置的 url 为 /get/moments
188+ POST http://localhost:8080/router/get/momentList // 对应 Document 表配置的 url
166189``` js
167190{
168- " format " : true ,
169- " Moment[].count" : 3 ,
170- " Moment[].page " : 1
191+ " Moment[].page " : 0 ,
192+ " Moment[].count" : 5 ,
193+ " format " : false
171194}
172195```
173196
174197如果 parser.isNeedVerifyContent,则会经过 Request 表校验规则来校验, <br />
175-
198+ If parser.isNeedVerifyContent, it will be validated with the rule in table Request < br />
176199
177200最后内部映射为: <br />
201+ Finally it will be mapped to: <br />
202+
178203``` js
179204{
180- " format" : true ,
181205 " Moment[]" : {
206+ " page" : 0 ,
207+ " count" : 5 ,
182208 " Moment" : {
183209 " @order" : " date-"
184- },
185- " page" : 1 ,
186- " count" : 3
187- }
210+ }
211+ },
212+ " format" : false
188213}
189214```
190215
191- 执行完 APIJSON 格式的请求后返回对应结果。
192-
216+ 执行完 APIJSON 格式的请求后返回对应结果 < br />
217+ Server will execute APIJSON request and response < br />
193218
219+ ![ image] ( https://user-images.githubusercontent.com/5738175/166560119-c598d3c6-48b6-4f47-85fe-8f36ca332e99.png )
194220
195- 注意:[ APIAuto] ( https://github.com/TommyLemon/APIAuto ) 不能自动获取并展示对应映射字段 showKey 的类型、长度、注释等文档,只能通过手写注释来实现 <br />
196- Note: [ APIAuto] ( https://github.com/TommyLemon/APIAuto ) cannot automatically get and show the document for the showKey, you can add comment manually.
197221
198222<br /><br />
199223
0 commit comments