@ alicloud/ pop- core
POP API的核心SDK.
安装
安装并写入 package.json 依赖性.
$ npm install @alicloud/pop-core -S
先决条件
节点.js >= 8.x
页:1
你必须知道你的 AK(单位:千美元)accessKeyId/accessKeySecret),和云产品 endpoint 财务报告和审定财务报表 apiVersion。 。 。 .
例如,ECS OpenAPI(https://help.aliyun.com/document detail25490.html 页面存档备份,存于互联网档案馆),API版本为: 2014-05-26。 。 。 .
终点列表可见于 这里,中端点为ecs.aliyuncs.com. 添加 http 协议 http 或者说 https,应该是 http://ecs.aliyuncs.com/。 。 。 .
重要更新
- 从1.8.0版本开始,支持"身份证明提供商",并更新内部函数的签名逻辑. 改变内部逻辑要求的开发者需要注意这些变化.
在线演示
API 开发者门户 提供在线调用云产品OpenAPI的能力,并动态生成SDK示例代码和快速检索接口,这可以显著地降低使用云API的难度. 高度建议。 。 。 .
使用量
RPC 风格客户端 :
var RPCClient = require('@alicloud/pop-core').RPCClient;
var client = new RPCClient({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
endpoint: '<endpoint>',
apiVersion: '<apiVersion>'
});
// => returns Promise
client.request(action, params);
// co/yield, async/await
// options
client.request(action, params, {
timeout: 3000, // default 3000 ms
formatAction: true, // default true, format the action to Action
formatParams: true, // default true, format the parameter name to first letter upper case
method: 'GET', // set the http method, default is GET
headers: {}, // set the http request headers
});
ROA 风格客户端 :
var ROAClient = require('@alicloud/pop-core').ROAClient;
var client = new ROAClient({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<secretAccessKey>',
endpoint: '<endpoint>',
apiVersion: '<apiVersion>'
});
// => returns Promise
// request(HTTPMethod, uriPath, queries, body, headers, options);
// options => {timeout}
client.request('GET', '/regions');
// co/yield, async/await
自定义选择
我们提供两种方式来定制选择请求.
一种方法是选择通过客户端构建器。 您应该将通过构建器传递的选项视为默认自定义选项, 因为所有请求都会使用此选项 .
var client = new RPCClient({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
endpoint: '<endpoint>',
apiVersion: '<apiVersion>',
opts: {
timeout: 3000
}
});
另一种方法是通过函数的参数选择. 当您想要通过特定函数的选择时, 您应该使用这种方式 .
client.request(action, params, {
timeout: 3000
});
在使用两种方式时,选择会被合并. 但对于使用同一种密钥的选取,由函数参数提供的取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取.
Http 代理支持
var tunnel = require('tunnel-agent');
var RPCClient = require('@alicloud/pop-core').RPCClient;
var client = new RPCClient({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
endpoint: '<endpoint>',
apiVersion: '<apiVersion>'
});
client.request(action, params, {
agent: tunnel.httpOverHttp({
proxy: {
host: 'host',
port: port
}
});
});
许可证
麻省理工学院许可证