Skip to content

Latest commit

 

History

History
69 lines (54 loc) · 2.97 KB

ABServiceRequest.md

File metadata and controls

69 lines (54 loc) · 2.97 KB

ABServiceRequest ⇐ ABServiceCote

Kind: global class
Extends: ABServiceCote

abServiceRequest.request(key, data, [options], [cb]) ⇒ Promise

Send a request to another micro-service using the cote protocol. Accept an optional callback, but also returns a promise.

Kind: instance method of ABServiceRequest
Returns: Promise - resolves with the response from the service

Param Type Default Description
key string the service handler's key we are sending a request to.
data json the data packet to send to the service.
[options] object optional options
[options.timeout] number 5000 ms to wait before timing out
[options.maxAttempts] number 5 how many times to try the request if it fails
[options.longRequest] boolean false timeout after 90 seconds, will be ignored if timeout was set
[options.stringResult] boolean false Return the results as a string data type.
[cb] function optional node.js style callback(err, result) for when the response is received.

Example

// async/await
try {
   let result = await request(key, data);
} catch (err) {}
// promise
request(key, data, opts).then((result) => {}).catch((err) => {})
// callback
request(key, data, opts, (err, result) => {})
// or
request(key, data, (err, result) => {})

abServiceRequest.getRequester(domain, long)

Gets a cached requester for the domain, creating one if needed

Kind: instance method of ABServiceRequest

Param Type Description
domain string cote domain key
long boolean whether the requester needs a longer timeout

abServiceRequest.toParam(key, data)

toParam() repackage the current data into a common format between our services

Kind: instance method of ABServiceRequest

Param Type Description
key string The cote request key that identifies which service we are sending our request to.
data json The data packet we are providing to the service.