创建流控策略
功能介绍
当API上线后,系统会默认给每个API提供一个流控策略,API提供者可以根据自身API的服务能力及负载情况变更这个流控策略。
流控策略即限制API在一定长度的时间内,能够允许被访问的最大次数。
URI
HTTP/HTTPS请求方法以及URI如下表所示。
|
请求方法 |
URI |
|---|---|
|
POST |
/v1.0/apigw/throttles |
请求消息
|
参数 |
是否必选 |
类型 |
说明 |
|---|---|---|---|
|
name |
是 |
String |
流控策略名称。 支持汉字,英文,数字,下划线,且只能以英文和汉字开头,3 ~ 64字符。
说明:
中文字符必须为UTF-8或者unicode编码。 |
|
api_call_limits |
是 |
Integer |
API流量限制是指时长内一个API能够被访问的次数上限。该值不超过系统默认配额限制,系统默认配额为200tps,用户可根据实际情况修改该系统默认配额。输入的值不超过2147483647。正整数。 |
|
user_call_limits |
否 |
Integer |
用户流量限制是指一个API在时长之内每一个用户能访问的次数上限,该数值不超过API流量限制值。输入的值不超过2147483647。正整数。 |
|
app_call_limits |
否 |
Integer |
APP流量限制是指一个API在时长之内被每个APP访问的次数上限,该数值不超过用户流量限制值。输入的值不超过2147483647。正整数。 |
|
ip_call_limits |
否 |
Integer |
源IP流量限制是指一个API在时长之内被每个IP访问的次数上限,该数值不超过API流量限制值。输入的值不超过2147483647。正整数。 |
|
time_interval |
是 |
Integer |
流量控制的时长单位。与“流量限制次数”配合使用,表示单位时间内的API请求次数上限。输入的值不超过2147483647。正整数。 |
|
time_unit |
是 |
String |
流控的时间单位:
|
|
remark |
否 |
String |
流控策略描述 字符长度不超过255。
说明:
中文字符必须为UTF-8或者unicode编码。 |
|
type |
否 |
Integer |
流控策略的类型,取值如下:
|
|
enable_adaptive_control |
否 |
String |
是否开启动态流控:
暂不支持 |
请求消息样例:
{
"api_call_limits": 800,
"user_call_limits": 500,
"app_call_limits": 300,
"ip_call_limits": 600,
"name": "每秒800次",
"remark": "API每秒800次,用户500次,APP300次,IP600次",
"time_interval": 1,
"time_unit": "SECOND"
}
响应消息
|
参数 |
类型 |
说明 |
|---|---|---|
|
id |
String |
流控策略的编号 |
|
name |
String |
流控策略的名称 |
|
api_call_limits |
Integer |
单个API流控时间内能够被访问的次数限制 |
|
user_call_limits |
Integer |
单个用户流控时间内能够访问API的次数限制 |
|
app_call_limits |
Integer |
单个APP流控时间内能够访问API的次数限制 |
|
ip_call_limits |
Integer |
单个IP流控时间内能够访问API的次数限制 |
|
time_interval |
Integer |
流控的时长 |
|
time_unit |
String |
流控的时间单位 |
|
remark |
String |
描述 |
|
create_time |
Timestamp |
创建时间 |
|
is_include_special_throttle |
Integer |
是否包含特殊流控配置:
|
|
type |
Integer |
流控策略的类型,取值如下:
|
|
bind_num |
Integer |
流控绑定的API数量 |
|
enable_adaptive_control |
String |
是否开启动态流控:
暂不支持 |
响应消息样例:
{
"id": "0325b671-2d50-4614-9868-22102262695d",
"name": "每秒800次",
"api_call_limits": 800,
"user_call_limits": 500,
"app_call_limits": 300,
"ip_call_limits": 600,
"time_interval": 1,
"time_unit": "SECOND",
"create_time": "2017-12-29T01:55:59.9904225Z",
"remark": "API每秒800次,用户500次,APP300次,IP600次",
"is_inclu_special_throttle": 2,
"type":1,
"bind_num": 0,
"enable_adaptive_control": "FALSE"
}
状态码
|
状态码 |
说明 |
|---|---|
|
201 |
Created |
|
400 |
Bad Request |
|
401 |
Unauthorized |
|
500 |
Server Internal Error |