项目作者: capabilityio

项目描述 :
Capability SDK for Node.js.
高级语言: JavaScript
项目地址: git://github.com/capabilityio/capability-sdk-js.git
创建时间: 2017-12-12T00:01:57Z
项目社区:https://github.com/capabilityio/capability-sdk-js

开源协议:Apache License 2.0

下载


capability-sdk

Stability: 0 - Deprecated

Capability SDK for Node.js.

Contents

Installation

  1. npm install capability-sdk

Usage

SDK can be require‘d in your Node.js application via require().

  1. const CapabilitySDK = require("capability-sdk");

Tests

No tests at this time.

Documentation

CapabilitySDK.request(capability, options, callback)

  • capability: Capability URI Capability to use.
  • options: Object HTTPS request options, if any. Hostname, port, and authorization header will be overriden by the specified capability.
  • callback: Function (resp) => {} (Default: undefined) Optional callback that will be added as one time listener for the “response” event.
  • Return: http.ClientRequest Node.js HTTP ClientRequest object.

Creates an HTTPS request using the provided capability and HTTP options. For example:

  1. const capability = "cpblty://membrane.amzn-us-east-1.capability.io/#CPBLTY1-aqp9nlT7a22dTGhks8vXMJNabKyIZ_kAES6U87Ljdg73xXiatBzgu5tImuWjFMXicgYb3Vpo0-C6mbm5_uFtAA";
  2. const req = CapabilitySDK.request(capability);
  3. req.on("response", resp =>
  4. {
  5. console.log(`STATUS: ${resp.statusCode}`);
  6. console.log(`HEADERS: ${JSON.stringify(resp.headers)}`);
  7. resp.setEncoding('utf8');
  8. resp.on("data", chunk => console.log(`BODY: ${chunk}`));
  9. resp.on("end", () => console.log("No more data in response."));
  10. }
  11. );
  12. req.on("error", error =>
  13. {
  14. console.error(`problem with request: ${error.message}`);
  15. }
  16. );
  17. req.write("my data to write");
  18. req.end();

CapabilitySDK.requestReply(capability, options, data, callback)

  • capability: Capability URI Capability to use.
  • options: Object HTTPS request options, if any. Hostname, port, and authorization header will be overriden by the specified capability.
  • data: String (Default: undefined) Request data to send, if any.
  • callback: Function (error, resp) => {}
    • error: Error Error, if any.
    • resp: Object Response object.

Creates an HTTPS request, sends data in the request, awaits JSON response, parses JSON response and/or error and calls callback with error or response. For example:

  1. const capability = "cpblty://membrane.amzn-us-east-1.capability.io/#CPBLTY1-hcghmWpaSIR6mi7Qf1wTm4StWzckTNeYoVZhmyCZ9p5tkjrgpFS1hXOo3nQ60exxooUhX9Oo6JJVuAMlVFiNkg";
  2. const payload = JSON.stringify({hi: "o/"});
  3. CapabilitySDK.requestReply(
  4. capability,
  5. {
  6. headers:
  7. {
  8. "Content-Length": Buffer.byteLength(payload, "utf8")
  9. }
  10. },
  11. payload,
  12. (error, resp) =>
  13. {
  14. if (error)
  15. {
  16. console.error(error);
  17. }
  18. console.log(resp);
  19. }
  20. );

CapabilitySDK.version

Property containing the capability-sdk module version being used.

Releases

Policy

We follow the semantic versioning policy (semver.org) with a caveat:

Given a version number MAJOR.MINOR.PATCH, increment the:

MAJOR version when you make incompatible API changes,

MINOR version when you add functionality in a backwards-compatible manner, and

PATCH version when you make backwards-compatible bug fixes.

caveat: Major version zero is a special case indicating development version that may make incompatible API changes without incrementing MAJOR version.