Skip to content

Commit 897edce

Browse files
author
fengyikai
committed
支持自定义Header
1 parent 22a62db commit 897edce

5 files changed

Lines changed: 38 additions & 82 deletions

File tree

README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,44 @@
3131
```js
3232
const kscSdk = require('ksyun-sdk-node')
3333

34-
const Client = kscSdk.Iam.v20151101
34+
const IamClient = kscSdk.Iam.v20151101
3535
const clientConfig = {
36-
// 认证信息
37-
credential: {
38-
secretId: '',
39-
secretKey: '',
40-
},
41-
// 产品地域
42-
region: "cn-beijing-6",
43-
// 可选配置实例
44-
httpProfile: {
45-
method: 'POST', // 请求方法 GET 或者 POST
46-
timeout: 60, // 请求超时时间秒
47-
protocol: '', // 协议 http:// 或者 https://
48-
endpoint: '' // 接入点域名 如 iam.api.ksyun.com
49-
},
36+
// 认证信息
37+
credential: {
38+
secretId: "KSYUN_SECRET_ID_HERE",
39+
secretKey: "KSYUN_SECRET_KEY_HERE",
40+
},
41+
// 产品地域
42+
region: "cn-beijing-6",
43+
// 可选配置实例
44+
httpProfile: {
45+
method: 'POST',
46+
timeout: 60, // 请求超时时间秒
47+
protocol: '',
48+
endpoint: 'iam.api.ksyun.com',
49+
},
5050
}
51-
let client = new Client(clientConfig)
51+
let client = new IamClient(clientConfig)
5252

5353
/**
5454
* client.request 参数
5555
* @param {string} apiAction 接口名
5656
* @param {object} data 参数
5757
*/
5858

59-
let apiAction = 'GetUser'
59+
let apiAction = 'ListUsers'
6060
let data = {
61-
"UserName": "test14"
61+
"MaxItems": 100
6262
}
6363

6464
client.request(apiAction, data)
65-
.then(res => res.json())
66-
.then(data => {
67-
console.log(JSON.stringify(data))
68-
})
69-
.catch(err => {
70-
console.log(err)
71-
})
65+
.then(res => res.json())
66+
.then(data => {
67+
console.log(JSON.stringify(data))
68+
})
69+
.catch(err => {
70+
console.log(err)
71+
})
7272
```
7373

7474
# 更多示例

example/iam.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
const kscSdk = require('../src/index.js')
1+
const kscSdk = require('ksyun-sdk-node')
22

3-
const Client = kscSdk.Iam.v20151101
3+
const IamClient = kscSdk.Iam.v20151101
44
const clientConfig = {
55
// 认证信息
66
credential: {
7-
secretId: '',
8-
secretKey: '',
7+
secretId: "KSYUN_SECRET_ID_HERE",
8+
secretKey: "KSYUN_SECRET_KEY_HERE",
99
},
1010
// 产品地域
1111
region: "cn-beijing-6",
1212
// 可选配置实例
1313
httpProfile: {
14-
method: 'POST', // 请求方法 GET 或者 POST
14+
method: 'POST',
1515
timeout: 60, // 请求超时时间秒
16-
protocol: '', // 协议 http:// 或者 https://
17-
endpoint: '', // 接入点域名 如 iam.api.ksyun.com
18-
path: '' // 自定义URL路径 如 /api/v1/xxx
16+
protocol: '',
17+
endpoint: 'iam.api.ksyun.com',
1918
},
2019
}
21-
let client = new Client(clientConfig)
20+
let client = new IamClient(clientConfig)
2221

2322
/**
2423
* client.request 参数
2524
* @param {string} apiAction 接口名
2625
* @param {object} data 参数
2726
*/
2827

29-
let apiAction = 'GetUser'
28+
let apiAction = 'ListUsers'
3029
let data = {
31-
"UserName": "test14"
30+
"MaxItems": 100
3231
}
3332

3433
client.request(apiAction, data)

example/res.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ksyun-sdk-node",
3-
"version": "1.5.8",
3+
"version": "1.5.9",
44
"description": "",
55
"main": "dist/index.js",
66
"scripts": {

src/base/BaseClient.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ module.exports = class BaseClient {
3636
let region = this.region || this._baseConfig.config.credentials.region
3737
let headers = {
3838
...(this._baseConfig.config.headers || {}),
39-
...(apiConfig.config.headers || {})
39+
...(apiConfig.config.headers || {}),
40+
...(this.httpProfile.headers || {})
4041
}
4142

4243
// 处理自定义path

0 commit comments

Comments
 (0)