lib 中文文档教程

发布于 2年前 浏览 8 项目主页 更新于 2年前

Autocode 标准库 Node.js 绑定

用于 Autocode 标准库服务接入 (Node 4+) 的基本节点绑定。

用于与使用 Autocode 构建的服务进行交互 自动编码 CLI

lib 包可在 npm: lib 上找到,并且 作为零依赖接口运行 Autocode 标准库 API 和 网页服务。 这意味着您可以使用 Autocode 上的任何服务,而无需 安装任何其他依赖项,并且当您将服务部署到 Autocode 时, 例如,您有一个预构建的 Node.js SDK;

回调样式

const lib = require('lib');
lib.yourUsername.hostStatus({name: 'Dolores Abernathy'}, (err, result) => {

  // handle result

});

Promise 样式

const lib = require('lib');
lib.yourUsername.hostStatus({name: 'Dolores Abernathy'})
  .then(result => /* handle result */)
  .catch(err => /* handle error */);

要探索 Autocode 标准库,请访问 https://autocode.com/lib/。 要构建 Web 服务或标准库 API,请在 https://autocode.com/ 上注册。

安装

要在项目中本地安装,请使用;

$ npm install lib --save

使用

const lib = require('lib');

// [1]: Call "utils.greet" function, the latest version, from Autocode
let message = await lib.utils.greet({name: 'Lionel Hutz'});

// [2]: Call "utils.greet" function with "dev" environment
let message = await lib.utils.greet['@dev']({name: 'Lionel Hutz'});

// [3]: Call "utils.greet" function with "release" environment
//      This is equivalent to (1)
let message = await lib.utils.greet['@release']({name: 'Lionel Hutz'});

// [4]: Call "utils.greet" function with specific version
//      if latest version, this is equivalent to (1)
let message = await lib.utils.greet['@0.0.1']({name: 'Lionel Hutz'});

// [5]: Call another endpoint within the "utils.greet" service
let message = await lib.utils.greet['@dev'].otherEndpoint();

// You can compose calls dynamically as well by using a string key
await lib['utils.greet']({name: 'Lionel Hutz'});
await lib['utils.greet[@dev]']({name: 'Lionel Hutz'});
await lib['utils.greet[@release]']({name: 'Lionel Hutz'});
await lib['utils.greet[@0.0.1]']({name: 'Lionel Hutz'});
await lib['utils.greet.otherEndpoint']({name: 'Lionel Hutz'});
await lib['utils.greet[@dev].otherEndpoint']({name: 'Lionel Hutz'});
await lib['utils.greet[@release].otherEndpoint']({name: 'Lionel Hutz'});
await lib['utils.greet[@0.0.1].otherEndpoint']({name: 'Lionel Hutz'});

附加信息

要了解有关 Autocode 的更多信息,请访问 autocode.com 或阅读 GitHub 上的自动编码 CLI 文档

您可以在 Twitter 上关注开发团队,@AutocodeHQ

Autocode 版权所有 © 2016 - 2021 Polybit Inc.

Autocode standard library Node.js bindings

Basic Node bindings for Autocode standard library service accession (Node 4+).

Used to interface with services built using Autocode and the Autocode CLI.

The lib package is available on npm: lib and operates as zero-dependency interface to run Autocode standard library APIs and web services. This means that you can utilize any service on Autocode without installing any additional dependencies, and when you've deployed services to Autocode, you have a pre-built Node.js SDK --- for example;

Callback Style

const lib = require('lib');
lib.yourUsername.hostStatus({name: 'Dolores Abernathy'}, (err, result) => {

  // handle result

});

Promise Style

const lib = require('lib');
lib.yourUsername.hostStatus({name: 'Dolores Abernathy'})
  .then(result => /* handle result */)
  .catch(err => /* handle error */);

To explore the Autocode standard library, visit https://autocode.com/lib/. To build a web service or standard library API, sign up on https://autocode.com/.

Installation

To install locally in a project, use;

$ npm install lib --save

Usage

const lib = require('lib');

// [1]: Call "utils.greet" function, the latest version, from Autocode
let message = await lib.utils.greet({name: 'Lionel Hutz'});

// [2]: Call "utils.greet" function with "dev" environment
let message = await lib.utils.greet['@dev']({name: 'Lionel Hutz'});

// [3]: Call "utils.greet" function with "release" environment
//      This is equivalent to (1)
let message = await lib.utils.greet['@release']({name: 'Lionel Hutz'});

// [4]: Call "utils.greet" function with specific version
//      if latest version, this is equivalent to (1)
let message = await lib.utils.greet['@0.0.1']({name: 'Lionel Hutz'});

// [5]: Call another endpoint within the "utils.greet" service
let message = await lib.utils.greet['@dev'].otherEndpoint();

// You can compose calls dynamically as well by using a string key
await lib['utils.greet']({name: 'Lionel Hutz'});
await lib['utils.greet[@dev]']({name: 'Lionel Hutz'});
await lib['utils.greet[@release]']({name: 'Lionel Hutz'});
await lib['utils.greet[@0.0.1]']({name: 'Lionel Hutz'});
await lib['utils.greet.otherEndpoint']({name: 'Lionel Hutz'});
await lib['utils.greet[@dev].otherEndpoint']({name: 'Lionel Hutz'});
await lib['utils.greet[@release].otherEndpoint']({name: 'Lionel Hutz'});
await lib['utils.greet[@0.0.1].otherEndpoint']({name: 'Lionel Hutz'});

Additional Information

To learn more about Autocode, visit autocode.com or read the Autocode CLI documentation on GitHub.

You can follow the development team on Twitter, @AutocodeHQ

Autocode is © 2016 - 2021 Polybit Inc.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文