ZetaAPI動態(tài)生成 Api 文檔
ZetaAPI 是一個使用 SQL + XML 快速創(chuàng)建 Api 接口與使用文檔的框架,幫助開發(fā)者提升開發(fā)效率。
框架特性
- 配置簡單功能豐富
- 使用xml標(biāo)簽屬性就可支持緩存,默認(rèn)緩存實現(xiàn)為caffeine,也可自定義緩存實現(xiàn)
- 標(biāo)簽內(nèi)if分支判斷,用于處理各種復(fù)雜場景
- 自定義訪問攔截,可通過創(chuàng)建攔截器修改表達(dá)式與返回結(jié)果
- 動態(tài)生成Api文檔,可以方便的查看API接口,支持在線測試與接口編輯
- 支持xml熱更新,無需重啟容器,即可讀取最新xml配置
使用方法
- 創(chuàng)建spring boot項目,添加zeta-api依賴
- 配置數(shù)據(jù)庫連接與數(shù)據(jù)庫驅(qū)動
- 入口類設(shè)置注解掃描路徑 @SpringBootApplication(scanBasePackages = "xyz.erupt")
- 創(chuàng)建配置文件,/resources/epi/xxx.xml
- xml文件示范例
<?xml version="1.0" encoding="utf-8" ?>
<zeta desc="zeta接口示例">
<hello-world title="基礎(chǔ)使用">
select 'hello world' $key
</hello-world>
<cache cache="5000" title="使用緩存(cache單位毫秒)">
select 'cache',now() now
</cache>
<params title="參數(shù)獲取與處理">
<param key="param" default="hello zeta" title="返回值"/>
select :param param
</params>
<condition title="條件處理">
<param key="param" default="" title="數(shù)值"/>
select
<if test="param > 10">
'gt 10' param_status
</if>
<if test="param < 10">
'lt 10' param_status
</if>
<if test="param == 10">
'eq 10' param_status
</if>
</condition>
<insert title="插入數(shù)據(jù)">
<param key="content" title="待插入數(shù)據(jù)"/>
insert into demo(content) values (:content)
</insert>
</zeta>
啟動項目,查看接口文檔:http://host/zeta?doc/host/zeta?doc/{xml文件名}.html
application.yml配置項說明
zeta-api: #是否熱讀取xml配置,生產(chǎn)環(huán)境不要開啟此功能 hotReadXml: true #是否開始緩存功能 enableCache: true #是否開啟Api文檔查詢功能 enableApiDoc: true #自定義緩存實現(xiàn),需實現(xiàn)xyz.erupt.zeta_api.handler.ZetaCache接口 cacheHandlerPath: xyz.erupt.xxxx #是否打印sql語句 showSql: true #訪問白名單,空表示不對ip進(jìn)行鑒權(quán) ipWhite: - 127.0.0.1 - 192.168.1.1 - 192.168.1.187
接口請求示例
// jquery為例
$.ajax({
type: "POST",
url: "/zeta-api/sql/{file}/{name}",
contentType: "application/json", //請求內(nèi)容需要為json
data: JSON.stringify({ param: 10}), //必須使用JSON.stringify
success: function (res) {
alert(res);
}
});
評論
圖片
表情
