1.1.0 • Published 5 years ago
tc2-domain-api v1.1.0
腾讯云 云解析API
- 支持 TypeScript
- 完整的类型定义
- 支持 GET and POST
- 支持
HmacSHA1
andHmacSHA256
加密算法 - 使用强大更易使用axios进行数据发送
安装 (Installing)
npm:
$ npm install tc2-domain-api
yarn:
$ yarn add tc2-domain-api
例子 Example
const { TCDomainAPI } = require('tc2-domain-api');
const api = new TCDomainAPI({
// options...
});
// use Promise
api.domainList().then(r => console.log);
// use async Function
async function domList() {
try {
const r = await api.domainList();
} catch(e) { }
}
import { TCDomainAPI } from 'tc2-domain-api';
const api = new TCDomainAPI({
// options...
});
api.recordList({
domain: 'example.com'
}).then((result) => {
if (result.data.ok) {
// 正确的类型推论
// Correct type inference
} else {
// 错误的类型定义 需要你来定义
// Wrong type definition, you need to define
}
});
// 定义错误的类型
// Define wrong
interface IWrongType {
// You define types
}
//
api.recordList<IWrongType>({
domain: 'example.com'
}).then((result) => {
if (result.data.ok) {
// 正确的类型推论
// Correct type inference
} else {
// 错误的类型定义 需要你来定义
// Wrong type definition, you need to define
// 正确推论出错误类型
// Correct inference of the type of error
}
});
options:
export interface IConfig {
/**
* 在[云API](https://cloud.tencent.com/login)密钥上申请的标识身份的 SecretId,一个 SecretId 对应唯一的 SecretKey , 而 SecretKey 会用来生成请求签名 Signature。
* 具体可参考 [签名方法](https://cloud.tencent.com/document/api/377/4214) 页面。
*/
SecretId: string;
/**
* 用于签名
*/
SecretKey: string;
/**
* 可选 hash 算法 'HmacSHA1' | 'HmacSHA256'
* 默认 'HmacSHA1'
*/
SignatureMethod?: ShaType;
/**
* 选择传送方式默认 GET 可选 GET | POST
*/
method?: Methods;
/**
* 因为基于axios进行发送请求所以你可以进行一些额外的配置,
* 你的配置将会通过
* ```ts
* Object.assign(defaultConfig[, you config])
* ```
* 进行简单合并所以你的优先级大于defaultConfig
*
* ```ts
* // 默认配置
* {
* baseURL: 'https://cns.api.qcloud.com/v2/index.php',
* timeout: 1000 * 60 * 5, // 默认 五分钟后超时
* headers: {
* post: {
* 'content-type': 'application/x-www-form-urlencoded'
* }
* }
* }
* ```
*/
axiosConfig?: AxiosRequestConfig;
}
License
MIT