@volcengine/imagex-openapi
v2.2.0
Published
火山引擎视频云 Nodejs SDK,提供完备的 OPENAPI 请求调用能力
Downloads
22
Readme
@volcengine/imagex-openapi
Documentation
The documentation for the Volcengine VCloud API can be found here
The documentation for the nodejs SDK API can be found here
The documentation for the Volcengine AK&SK can be found here
Versions
@volcengine/imagex-openapi
uses a modified version of Semantic Versioning for all changes.
Supported Node.js Versions
This library supports Nodejs version 12 and above.
Sample Usage
Setting OpenAPI service's AK&SK
Available in three settings
1. By class initial options to set AK&SK
import VolcSdk from '@volcengine/imagex-openapi';
const client = new VolcSdk({
accessKey: 'your own accessKey',
secretKey: 'your own secretKey'
});
2. Use environment variables to set AK & SK
VOLC_ACCESSKEY="your ak" VOLC_SECRETKEY="your sk"
3. Use configuration file
Put it in ~/.volc/config in json format, the format is:
{"VOLC_ACCESSKEY":"your ak","VOLC_SECRETKEY":"your sk"}
Specify Region and/or Host
You could specify the target Region and/or Host for the client:
import VCloudSdk from '@volcengine/imagex-openapi';
const client = new VCloudSdk({
accessKey: 'your own accessKey',
secretKey: 'your own secretKey',
region: 'cn-north-1',
host: 'open.volcengineapi.com'
});
Logging and custom log
To log this SDK request, you could set the logLevel or set your own application log policy by setting LoggerOptions.log method.
import VCloudSdk from '@volcengine/imagex-openapi';
import winston from 'winston';
const appLogger = winston.createLogger();
const client = new VCloudSdk({
accessKey: 'your own accessKey',
secretKey: 'your own secretKey',
loggerOptions: {
level: 'debug',
log: function(opts) {
appLogger.log(opts);
},
},
});
Using a Custom HTTP Request Client
The Volcengine VCloud nodejs SDK uses axios, a promise-based HTTP client, to make requests. You can also provide your own httpClient to customize requests as needed.
import VCloudSdk from '@volcengine/imagex-openapi';
import customHttpRequest from './customHttpRequest';
const client = new VCloudSdk({
accessKey: 'your own accessKey',
secretKey: 'your own secretKey',
region: 'cn-north-1',
host: 'open.volcengineapi.com',
httpRequest: customHttpRequest,
});
Write a custom HTTP client
async function request(url, options) {
const { headers = {}, proxy, maxBodyLength = 0 } = options;
const reqOption: AxiosRequestConfig = {
url,
...options,
headers: {
...headers,
'User-Agent': 'your own user agent'
}
};
try {
const res = await axios(reqOption);
return {status: res.status, body: res.data, headers: res.headers};
} catch(e) {
// report metrics and so on...
}
}
Use a custom HTTP client with this SDK, you could mock the Volcengine API responses, and run your unit and integration tests quickly without the need to make a connection to Volcengine.
plugin
If the current features can't meet your needs, you can try to write a custom plugin following the next format
function plugin () {
return async (context, next) => {
// ...
// execute before send request
await next() // execute the rest plugins and send request at last
// execute after send request
// ...
}
}
there is a simple example
export default function accessPlugin() {
return async (context, next) => {
if(checkAccess()) {
await next();
} else {
context.response = 'has no access';
}
return;
};
}
then you need to register this plugin to a client
const client = new VCloudSdk({
accessKey: 'your own accessKey',
secretKey: 'your own secretKey',
region: 'cn-north-1',
host: 'open.volcengineapi.com',
httpRequest: customHttpRequest,
});
client.addPlugin(accessPlugin);
Proxy Settings
To make request via a proxy host, you could set the proxy options.
1. By class initial options to set proxy
import VCloudSdk from '@volcengine/imagex-openapi';
const client = new VCloudSdk({
accessKey: 'your own accessKey',
secretKey: 'your own secretKey',
proxy: {
protocol: 'https',
host: 'your own proxy host ip',
auth: 'your own proxy host auth',
port: 8080, // your own proxy host port
}
});
2.Use environment variables to set proxy.
VOLC_PROXY_HOST="your own proxy host" VOLC_PROXY_PORT="your own proxy host port"
Getting help
If you need help installing or using the sdk, please check the Volcengine Support Help Center first.
If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!