@alicloud/pop-core

中文文档
1.8.0发布于 2024/12/09MITTypeScriptCommonJS近 30 天下载 12.5万

AliCloud POP SDK core

原始使用文档
文档目录9 节
  1. Installation
  2. Prerequisite
  3. Notes
  4. Important Updates
  5. Online Demo
  6. Usage
  7. Custom opts
  8. Http Proxy Support
  9. License

@alicloud/pop-core

The core SDK of POP API.

NPM version build status codecov

Installation

Install it and write into package.json dependences.

$ npm install @alicloud/pop-core -S

Prerequisite

Node.js >= 8.x

Notes

You must know your AK(accessKeyId/accessKeySecret), and the cloud product's endpoint and apiVersion.

For example, The ECS OpenAPI(https://help.aliyun.com/document_detail/25490.html), the API version is 2014-05-26.

And the endpoint list can be found at here, the center endpoint is ecs.aliyuncs.com. Add http protocol http or https, should be http://ecs.aliyuncs.com/.

Important Updates

  • Starting from version 1.8.0, CredentialsProvider is supported, and the signature logic of internal functions is updated. Developers who change the internal logic for calling need to pay attention to these changes.

Online Demo

API Developer Portal provides the ability to call the cloud product OpenAPI online, and dynamically generate SDK Example code and quick retrieval interface, which can significantly reduce the difficulty of using the cloud API. It is highly recommended.

Usage

The RPC style client:

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
});

The ROA style client:

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

Custom opts

We offer two ways to customize request opts.

One way is passing opts through the Client constructor. You should treat opts passed through the constructor as default custom opts, because all requests will use this opts.

var client = new RPCClient({
  accessKeyId: '<accessKeyId>',
  accessKeySecret: '<accessKeySecret>',
  endpoint: '<endpoint>',
  apiVersion: '<apiVersion>',
  opts: {
    timeout: 3000
  }
});

Another way is passing opts through the function's parameter. You should use this way when you want to just pass opts in specific functions.

client.request(action, params, {
  timeout: 3000
});

When both ways are used, opts will be merged. But for the opt with the same key, the opts provided by the function parameter overrides the opts provided by the constructor.

Http Proxy Support

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
    }
  });
});

License

The MIT License

版本与发布记录

@alicloud/pop-core 共发布 45 个版本,首次发布于 2017/01/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.8.0latest2024/12/091.9 年前
1.7.132023/04/273 年前
1.7.122022/06/134 年前
1.7.112022/05/234 年前
1.7.102020/10/226 年前
1.7.92019/12/186 年前

关于 @alicloud/pop-core 的常见问题

@alicloud/pop-core 是什么?

AliCloud POP SDK core

如何安装 @alicloud/pop-core?

在项目目录运行 npm install @alicloud/pop-core,或使用 pnpm add / yarn add / bun add。

@alicloud/pop-core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alicloud/pop-core 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@alicloud/pop-core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=8.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@alicloud/pop-core 可以商用吗?

@alicloud/pop-core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@alicloud/pop-core 的下载量有多少?

根据 npm 官方下载统计,@alicloud/pop-core 在 2026/10/06 – 2026/11/04 这 30 天内被下载 125,255 次,日均约 4,175 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alicloud/pop-core 还在维护吗?

最新版本 1.8.0 发布于 2024/12/09(1.9 年前);至今共发布 45 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/01/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。