3thisistest 中文文档教程
Getting started
APIMATIC 上托管
How to Build
的简单计算器 API 生成的 SDK 依赖于 Node Package Manager (NPM) 可用于解决依赖关系。 如果您尚未安装 NPM,请继续并按照说明从此处 安装 NPM。 SDK 还需要安装 Node。 如果尚未安装 Node,请从 此处
安装 Node 时默认安装 NPM
检查节点和 已成功安装,在命令提示符中写入以下命令:
node --version
npm -version
npm
现在使用 npm 通过在根目录(SDK 文件夹)中运行以下命令来解决所有依赖项:
npm install
这将在 node_modules文件夹。
解决依赖关系后,您需要将文件夹 APIMATICCalculatorLib
移动到您的 node_modules
文件夹中。
How to Use
以下部分解释了如何在新项目中使用该库。
1. Open Project Folder
打开 JavaScript 的 IDE/文本编辑器,例如 Sublime Text。 如果您更喜欢使用不同的编辑器或 IDE,此处介绍的基本工作流程也适用。
点击文件
并选择打开文件夹
。
选择您的 SDK 的文件夹并点击 Select Folder
打开它在 Sublime Text 中。 该文件夹将在左侧的栏中可见。
2. Creating a Test File
现在右键单击文件夹名称并选择 New File
选项来创建一个新的测试文件。 将其保存为 index.js
现在使用以下代码行导入生成的 NodeJS 库:
var lib = require('lib');
保存更改。
3. Running The Test File
要运行 index.js
文件,请打开命令提示符并导航到路径SDK 文件夹所在。 键入以下命令以运行文件:
node index.js
How to Test
这些测试使用 Mocha 框架用于测试,与 Chai 一起用于断言。 需要安装这些依赖项才能运行测试。 可以通过多种方式运行测试:
Method 1 (Run all tests)
- Navigate to the root directory of the SDK folder from command prompt.
- Type
mocha --recursive
to run all the tests.
Method 2 (Run all tests)
- Navigate to the
../test/Controllers/
directory from command prompt. - Type
mocha *
to run all the tests.
Method 3 (Run specific controller's tests)
- Navigate to the
../test/Controllers/
directory from command prompt. - Type
mocha APIMATIC CalculatorController
to run all the tests in that controller file.
要增加 mocha 的默认超时,您可以更改
TestBootstrap.js
中的TEST_TIMEOUT
参数值。
Initialization
API 客户端可以初始化如下:
const lib = require('lib');
Class Reference
List of Controllers
SimpleCalculatorController
Get singleton instance
的单例实例可以从 API 客户端访问 SimpleCalculatorController
类。
var controller = lib.SimpleCalculatorController;
getCalculate
使用指定的运算计算表达式。
function getCalculate(input, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
operation | Required | The operator to apply on the variables |
x | Required | The LHS value |
y | Required | The RHS value |
Example Usage
var input = [];
input['operation'] = new OperationTypeEnum(MULTIPLY);
input['x'] = 4;
input['y'] = 5;
controller.getCalculate(input, function(error, response, context) {
});
Getting started
Simple calculator API hosted on APIMATIC
How to Build
The generated SDK relies on Node Package Manager (NPM) being available to resolve dependencies. If you don't already have NPM installed, please go ahead and follow instructions to install NPM from here. The SDK also requires Node to be installed. If Node isn't already installed, please install it from here
NPM is installed by default when Node is installed
To check if node and npm have been successfully installed, write the following commands in command prompt:
node --version
npm -version
Now use npm to resolve all dependencies by running the following command in the root directory (of the SDK folder):
npm install
This will install all dependencies in the node_modules
folder.
Once dependencies are resolved, you will need to move the folder APIMATICCalculatorLib
in to your node_modules
folder.
How to Use
The following section explains how to use the library in a new project.
1. Open Project Folder
Open an IDE/Text Editor for JavaScript like Sublime Text. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
Click on File
and select Open Folder
.
Select the folder of your SDK and click on Select Folder
to open it up in Sublime Text. The folder will become visible in the bar on the left.
2. Creating a Test File
Now right click on the folder name and select the New File
option to create a new test file. Save it as index.js
Now import the generated NodeJS library using the following lines of code:
var lib = require('lib');
Save changes.
3. Running The Test File
To run the index.js
file, open up the command prompt and navigate to the Path where the SDK folder resides. Type the following command to run the file:
node index.js
How to Test
These tests use Mocha framework for testing, coupled with Chai for assertions. These dependencies need to be installed for tests to run. Tests can be run in a number of ways:
Method 1 (Run all tests)
- Navigate to the root directory of the SDK folder from command prompt.
- Type
mocha --recursive
to run all the tests.
Method 2 (Run all tests)
- Navigate to the
../test/Controllers/
directory from command prompt. - Type
mocha *
to run all the tests.
Method 3 (Run specific controller's tests)
- Navigate to the
../test/Controllers/
directory from command prompt. - Type
mocha APIMATIC CalculatorController
to run all the tests in that controller file.
To increase mocha's default timeout, you can change the
TEST_TIMEOUT
parameter's value inTestBootstrap.js
.
Initialization
API client can be initialized as following:
const lib = require('lib');
Class Reference
List of Controllers
SimpleCalculatorController
Get singleton instance
The singleton instance of the SimpleCalculatorController
class can be accessed from the API Client.
var controller = lib.SimpleCalculatorController;
getCalculate
Calculates the expression using the specified operation.
function getCalculate(input, callback)
Parameters
Parameter | Tags | Description |
---|---|---|
operation | Required | The operator to apply on the variables |
x | Required | The LHS value |
y | Required | The RHS value |
Example Usage
var input = [];
input['operation'] = new OperationTypeEnum(MULTIPLY);
input['x'] = 4;
input['y'] = 5;
controller.getCalculate(input, function(error, response, context) {
});