NodeJS SDKs will now return promises in endpoint calls, as an alternative to accepting callbacks.
- We use ES6 Promises which is based on Promises/A+ and is interoperable with most Promise-based implementations.
- Callbacks are still supported (for backward-compatibility) but are now optional.
Re-generate your NodeJS SDK to get the new Promise-enabled SDK implementation now.
Here is an except from a blog by StrongLoop:
All endpoint methods now return Promises.
let promise = apiController.endpointMethod();
onFulfilledmethod is called if the endpoint call succeeds and
onRejectedis called upon error.
onFulfilledmethod will be passed a response from the
endpointMethodif any, after validation.
onRejectedmethod will be passed an error object containing an
errorCodeor a custom error object if defined by your API description.
The sample code above can also be rewritten as:
An endpoint call's callback is always executed before its Promise is resolved.