Adobe I/O 核心网络Lib
安装
$ npm install @adobe/aio-lib-core-networking
使用量
- 初始化 SDK
const { HttpExponentialBackoff, createFetch } = require('@adobe/aio-lib-core-networking')
const fetchRetry = new HttpExponentialBackoff()
const proxyFetch = createFetch()
- 使用已初始化的 SDK 调用方法
const { HttpExponentialBackoff, createFetch } = require('@adobe/aio-lib-core-networking')
const fetchRetry = new HttpExponentialBackoff()
async function sdkTest() {
return new Promise((resolve, reject) => {
fetchRetry.exponentialBackoff(url, requestOptions, retryOptions, retryOn, retryDelay)
.then((response) => {
if (!response.ok) {
throw Error(reduceError(response))
}
resolve(response.json())
})
.catch(err => {
reject(
new codes.ERROR_GET_SOMETHING({ sdkDetails, messageValues: err }))
})
})
}
let proxyFetch
// this will get the proxy settings from the the HTTP_PROXY or HTTPS_PROXY environment variables, if set
proxyFetch = createFetch()
// this will use the passed in proxy settings. Embed basic auth in the url, if required
proxyFetch = createFetch({ proxyUrl: 'http://my.proxy:8080' })
// if the proxy settings are not passed in, and not available in the HTTP_PROXY or HTTPS_PROXY environment variables, it falls back to a simple fetch
const simpleFetch = createFetch()
类
职能
- 创建 Fetch( [代理选项]) ⇒
function 根据代理设置返回相应的获取函数 .
- 页眉后重写( 标题) ⇒
number 解析重试后页眉 谱: https://tools.ietf.org/html/rfc7231#section-7.1.3 页面存档备份,存于互联网档案馆
类型防御
责任 备份
此类提供了使用重试执行获取的方法 . 复试使用指数后退策略 默认值设置为最多 3次重试, 初始延迟为 100 秒
仁爱: 全球类
- 责任 备份
- 新建 Http 责任包( [选项])
- .expresentBackoff(url, request options, [重试可选), [重试可选), [重试延后] ⇒
Promise.<Response>
新建 Http 责任包( [选项])
创建 HtpExpentive 实例 备份
| 参数 | 类型 | 说明 |
|---|---|---|
| [可选 | object | 配置选项 |
| [选项.loglevel] | string | 要使用的日志级别( 默认: process.env.LOG LEVEL 或 “ info” ) |
| [可选.log Retry Afterseconds] (英语) | number | 如果 Retry-After 标题大于秒数,则记录警告的秒数。 设定为 0 以禁用 . |
httpExpensiveBackoff.expresentiveBackoff(url, request options, [重试可选), [重试可选], [重试可选), [重试可选) QQ Promise.<Response>
此函数将重试连接到 URL 端点, 与 指数反转。 返回承诺.
仁爱: 实例方法 HttpExponentialBackoff
回返数字 : Promise.<Response> - 代表http响应的承诺对象
| 参数 | 类型 | 说明 |
|---|---|---|
| url 密码 | string | 结束点 url |
| 选项 | object | Request | 请求选项 |
| [重试选项] | RetryOptions | (可选)重试选项 |
| [回 | function | Array | (可选)函数或矩阵 。 如果提供, 将使用默认 |
| [重试延 | function | number | (可选)函数或编号. 如果提供, 将使用默认 |
代理图像
这为获取提供了包装, 方便代理认证授权 .
仁爱: 全球类
- 代理图像
- 新建代理快取( 代理选项)
- .fetch( 资源, 选项) ⇒
Promise.<Response>
新建代理快取( 代理选项)
以代理认证选项初始化此类
| 参数 | 类型 | 说明 |
|---|---|---|
| 代理选项 | ProxyOptions | 连接到 |
代理切换. 切换( 资源, 选项) QQ Promise.<Response>
获取函数, 使用配置的获取选项, 和代理选项( 在构建器中设置) .
仁爱: 实例方法 ProxyFetch
回返数字 : Promise.<Response> - 代表http响应的承诺对象
| 参数 | 类型 | 说明 |
|---|---|---|
| 资源 | string | Request | 要获取的 URL 或请求的反对 |
| 选项 | object | 获取选项 |
创建 Fetch( [代理选项]] QQ function
根据代理设置返回相应的获取函数 .
仁爱:全球职能
回返数字 : function - 获取 API 函数
| 参数 | 类型 | 说明 |
|---|---|---|
| [替代选项] | ProxyOptions | 代理选项 |
解析后页眉( 标题) {} number
解析重试后页眉 谱: https://tools.ietf.org/html/rfc7231#section-7.1.3 页面存档备份,存于互联网档案馆
仁爱:全球职能
回返数字 : number - 要睡觉的毫秒数, 直到下一个呼叫, 获取EventsFromJournal
| 参数 | 类型 | 说明 |
|---|---|---|
| 标题 | string | 重试后页眉值 |
重试选项 : object
获取重试选项
仁爱: 全局类型def
属性
| 名称 | 类型 | 说明 |
|---|---|---|
| 最大存储量 | number | 尝试的最大重试次数( 默认 3) |
| 初始延迟 IMillis | number | 以毫秒计的初始延迟( 默认: 100ms) |
| 代理服务器 | ProxyOptions | (可选)代理认证选项 |
代理选项 : object
代理代理代理选项
仁爱: 全局类型def
属性
| 名称 | 类型 | 说明 |
|---|---|---|
| 代理用户 | string | 代理服务器的 url |
| [用户名] | string | 基本认证的用户名 |
| [口 | string | 基本认证的密码 |
| 拒绝未授权 | boolean | 设置为不拒绝未经授权的服务器证书 |
| [记录级别] | string | 要使用的日志级别( 默认: process.env.LOG LEVEL 或 “ info” ) |
除错日志
LOG_LEVEL=debug <your_call_here>
预留 LOG_LEVEL 环境变量和 debug 值到引用您函数的调用,在命令行上。 这将为您的 SDK 电话输出大量调试数据 .
捐款
欢迎捐款! 读取 贡献指南 更多信息.
许可证发放
这个项目根据Apache V2许可证获得许可. 见 自由主义 更多信息.