-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: chenhuanlin <[email protected]>
- Loading branch information
1 parent
1ca76c1
commit 0411392
Showing
17 changed files
with
478 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
7. `language` | ||
|
||
8. `avata` | ||
8. `avatar` | ||
{% endmacro %} | ||
|
||
# 获取用户信息 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# API 网关 | ||
|
||
知晓云 API 网关(API Gateway),是 API 发布、管理、运维的全生命周期管理工具。让开发者通过可视化界面配置并生成 API 提供给全平台使用,省掉了繁琐的服务开发及部署环节,五分钟即可完成 API 定制开发。 | ||
|
||
使用 API 网关,还可以让运行在知晓云上的应用数据得以更加灵活地提供给外部系统集成,无需再通过知晓云的 OpenAPI 进行数据转接,使得业务推进速度跃升一个等级。 | ||
|
||
> 知晓云控制台进入「引擎」即可开启使用。 | ||
## 创建 API 网关 | ||
|
||
选择「API 网关」tab,即可进入管理面板。 | ||
|
||
![创建 API 网关](/images/dashboard/api-gateway-creation.png) | ||
|
||
## 增加路由,绑定云函数 | ||
|
||
完成 API 网关创建后,在「API 管理」添加 API。 | ||
|
||
![创建 API](/images/dashboard/api-gateway-add-route.png) | ||
|
||
|
||
API 可以根据需求进行认证服务,请求参数等的前端配置,按需选择。 | ||
|
||
![API 前端配置](/images/dashboard/api-gateway-route-config.png) | ||
|
||
完成前端配置后,再进行后端云函数的配置,给正式/测试环境配置相对应的云函数,点击「新增云函数」会在新开的标签页中实现云函数的创建,完成后,点击刷新按钮即可选择。 | ||
|
||
![API 后端配置](/images/dashboard/api-gateway-route-associate-cloud-function.png) | ||
|
||
## 编写云函数 | ||
|
||
云函数中可使用的参数及返回数据都与普通云函数不一样,编写前先阅读[文档](/support/practice/api-gateway.md),确保编写出正确可用的云函数。 | ||
|
||
![云函数编写](/images/dashboard/api-gateway-create-cloud-function.png) | ||
|
||
编写成后,回到原有标签,进行关联操作。 | ||
|
||
![API 绑定云函数](/images/dashboard/api-gateway-choose-cloud-function.png) | ||
|
||
## 发布 API 网关 | ||
|
||
![API 发布](/images/dashboard/api-gateway-publish.png) | ||
|
||
## 验证 API 网关 | ||
|
||
![API 验证](/images/dashboard/api-gateway-verify.png) | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# API 网关定义 API 路径指南 | ||
|
||
API 路径是 URL 的组成一部分(path),具体含义可以参考:[什么是 URL](https://developer.mozilla.org/zh-CN/docs/Learn/Common_questions/What_is_a_URL) | ||
|
||
在 API 网关中 API 路径的定义有几个要求: | ||
|
||
1. 必须以 「/」 | ||
2. 仅限小写英文字母,不支持中文 | ||
3. 路径 + query string 的字符串长度不能超过 16k | ||
|
||
为了更好地丰富 API 路径的匹配模式,API 网关支持使用**正则表达式**来编写 API 路径。 | ||
|
||
|
||
## API 路径中的正则表达式语法 | ||
|
||
API 路径中使用正则表达式是为了实现从用户请求路径中获取符合某个条件的字符串(参数),所以使用的正则表达式会由匹配及重复字符组成。 | ||
|
||
格式: | ||
|
||
(<匹配字符><重复字符>) | ||
|
||
> 重复字符是用于描述匹配字符出现的重复次数才符合整个正则表达式。 | ||
> `()` 表示正则表达式的开始与结束 | ||
### 匹配字符 | ||
|
||
`[]` | ||
|
||
它用于指定匹配字符,可以单独列出字符,也可以通过给出两个字符并用 '-' 标记将它们分开来表示一系列字符。 | ||
|
||
例如,`[abc]` 将匹配任何字符 a、b 或 c,也可以写作 `[a-c]`,它使用一个范围来表示同一组字符。 | ||
|
||
`\d` | ||
|
||
匹配任何十进制数字。 | ||
|
||
`\D` | ||
|
||
匹配任何非数字字符。 | ||
|
||
`\w` | ||
|
||
匹配任何字母与数字字符 | ||
|
||
`\W` | ||
|
||
匹配任何非字母与数字字符 | ||
|
||
`.` | ||
|
||
匹配任何字符 | ||
|
||
|
||
### 重复字符 | ||
|
||
`*` | ||
|
||
匹配零或多次 | ||
|
||
`+` | ||
|
||
匹配一或多次 | ||
|
||
`{n}` | ||
|
||
n 是一个非负整数。匹配确定的 n 次 | ||
|
||
`{n,}` | ||
|
||
n 是一个非负整数。至少匹配 n 次 | ||
|
||
`{n,m}` | ||
|
||
m 和 n 均为非负整数,其中 n <= m,最少匹配 n 次且最多匹配 m 次 | ||
|
||
### 组合示例 | ||
|
||
`[abc]+` | ||
|
||
字符串中只能包含 `a`,`b`,`c` 三个字符串,匹配一或多次。 | ||
如 `a`,`aa`,`aaa`,`ab`,`bc`,`abbbbbc`匹配成功,`abd` 匹配失败。 | ||
|
||
`\d{1}` | ||
|
||
任何十进制数字匹配一次。 | ||
如 `1`,`2`... `9` 均能匹配成功,`10` 开始匹配失败。 | ||
|
||
|
||
## API 路径中的正则表达式使用 | ||
|
||
在 API 路径中写入正则表达式,API 网关捕获并将匹配到的字符串传入云函数中。 | ||
|
||
API 网关支持两种正则表达式的写法: | ||
|
||
1. 位置表达式 | ||
2. 命名表达式 | ||
|
||
> 需注意,不支持同时使用两种写法,如同时使用,则只会将匹配命名表达式的参数传入云函数 | ||
### 位置表达式 | ||
|
||
在 API 路径的任意位置中写入 `(pattern)` 即可完成。 | ||
|
||
下面是一个实际例子: | ||
|
||
/article/(\d+)/ | ||
|
||
当用户请求 `/article/1/` 在API 网关完成匹配后,云函数可通过 `event.request.meta.nested_arguments` 获取参数,event.request.meta 其数据结构为: | ||
|
||
{ | ||
"request_method": "GET", | ||
"nested_arguments": ["1"], | ||
"named_arguments": {}, | ||
"request_path": "/article/1/", | ||
"query_string": {}, | ||
"headers": {}, | ||
"ip_address": "127.0.0.1", | ||
"user_agent": "user-agent", | ||
} | ||
|
||
位置表达式可以写入多个 | ||
|
||
/article/(\d+)/(\w+)/ | ||
|
||
当用户请求 `/article/1/comment/` 在API 网关完成匹配后,云函数可通过 `event.request.meta.nested_arguments` 获取参数,event.request.meta 其数据结构为: | ||
|
||
{ | ||
"request_method": "GET", | ||
"nested_arguments": ["1", "comment"], | ||
"named_arguments": {}, | ||
"request_path": "/article/1/", | ||
"query_string": {}, | ||
"headers": {}, | ||
"ip_address": "127.0.0.1", | ||
"user_agent": "user-agent", | ||
} | ||
|
||
`event.request.meta.nested_arguments` 数组的中的顺序取决于每个位置表达式在 API 路径中的顺序。 | ||
|
||
### 命名表达式 | ||
|
||
命名表达式的语法与位置表达式不同,增加了参数命名: | ||
|
||
(?P<name>pattern) | ||
|
||
name 为对参数的命名,pattern 为正则表达式。下面是一个实际例子: | ||
|
||
/hello/(?P<id>\d+)/ | ||
|
||
当用户请求 `/hello/1` 在API 网关完成匹配后,云函数可通过 `event.request.meta.named_arguments` 获取参数,其数据结构为: | ||
|
||
{ | ||
"event.request.meta.named_arguments": { | ||
"id": "1" | ||
} | ||
} |
Oops, something went wrong.