api中台

AI智能底座

AI 光有大脑不行要有手去操作系统。调用企业资源。没有手脚的AI还是需要人来执行实际的操作工作。

api服务 就提供了企业内所有资源的使用接口,通过对接到各应用系统内的接口来完成一系列的工作。

大致架构

  • kong来做统一入口(前台归集资源)

  • node-red即时简单的iot

  • python自研业务逻辑

  • 多维表格简易人机接口 (缺少交互按钮)

  • Apifox/hoppscotch (单步验证)

kong适合api请求管理和域名映射管理 (应用代理)

简单转发

  1. 创建一个 Service:代表您的后端服务。
  2. 创建一个 Route:定义匹配客户端请求的规则。

curl -X POST http://127.0.0.1:8001/services/ \
  --header "Content-Type: application/json" \
  --data '{
    "name": "nodered-service",
    "url": "http://192.168.11.144:1880"
  }'


curl -X POST http://127.0.0.1:8001/services/nodered-service/routes \
  --header "Content-Type: application/json" \
  --data '{
    "name": "nodered-tget-route",
    "paths": ["/nodered"]
  }'

注意 公开访问路径是 /nodered/tget 后端服务路径是 /tget

erp地址转发


curl -X POST http://127.0.0.1:8001/services/ \
  --header "Content-Type: application/json" \
  --data '{
    "name": "k3cloud-service",
    "url": "http://192.168.0.48:80"
  }'
  
  
curl -X POST http://127.0.0.1:8001/services/k3cloud-service/routes \
  --header "Content-Type: application/json" \
  --data '{
    "name": "k3cloud-route",
    "paths": ["/k3cloud"],
    "strip_path": false
  }'

路径重写 (变路径)

curl -X POST http://127.0.0.1:8001/services/k3cloud-service/routes \
  --header "Content-Type: application/json" \
  --data '{
    "name": "oq-erp-route",
    "paths": ["/oq-erp"],
    "strip_path": false
  }'
  
  
  curl -X POST http://127.0.0.1:8001/routes/oq-erp-route/plugins \
  --header "Content-Type: application/json" \
  --data '{
    "name": "request-transformer",
    "config": {
      "replace": {
        "uri": "/k3cloud"
      }
    }
  }'

转发到群辉

路径剥离

curl -X POST http://127.0.0.1:8001/services/ \
  --header "Content-Type: application/json" \
  --data '{
    "name": "yynas-service",
    "url": "http://z4nas.17121.top:5000"
  }'
  
  
  curl -X POST http://127.0.0.1:8001/services/yynas-service/routes \
  --header "Content-Type: application/json" \
  --data '{
    "name": "yynas-route",
    "paths": ["/yynas"],
    "strip_path": true
  }'

域名转发

curl -X POST http://127.0.0.1:8001/services/ \
  --header "Content-Type: application/json" \
  --data '{
    "name": "yynas-domain-service",
    "url": "http://z4nas.17121.top:5000"
  }'
  
curl -X POST http://127.0.0.1:8001/services/yynas-domain-service/routes \
  --header "Content-Type: application/json" \
  --data '{
    "name": "yynas-domain-route",
    "hosts": ["l-yynas.ouqiyj.com"],
    "strip_path": false
  }'

常用转发

web文档


访问量分析

# 全局启用
curl -X POST http://127.0.0.1:8001/plugins/ \
  --header "Content-Type: application/json" \
  --data '{
    "name": "prometheus"
  }'

1小时内访问数据

http://192.168.0.123:8001/metrics