new module:request-response(inStream, outStream)
Creates a helper class used to send multiple messages back and forth across a read stream and a write stream
Terminates each complete message with a [q|s] character to indicate request or response, a white space padded 4 character request ID, followed by an ASCII Group Separator
Parameters:
Name | Type | Description |
---|---|---|
inStream |
external:Stream | The readable stream used in the communication |
outStream |
external:Stream | The writtable stream used in the communication |
Example
var requestHelper = new (require(request-response))(process.stdin, process.stdout);
Methods
(inner) pipeRequest(stream, callbackopt)
Pipes a new request into our managed output stream. Will not close the managed stream. Writes a requestId and request delimiter to the managed stream once the pipe is complete.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
stream |
external:Stream | The stream to pipe and decorate with a requestId | |
callback |
module:request-response~responseCallback |
<optional> |
A callback to use if this instance receives an incoming response with a matching requestId on the managed input stream |
(inner) writeRequest(msgBody, callbackopt)
Writes a new request into our managed output stream. Writes a requestId and request delimiter to the managed stream along with the message.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
msgBody |
string | The body of the request | |
callback |
module:request-response~responseCallback |
<optional> |
A callback to use if this instance receives a response with a matching requestId on the managed input stream |
(inner) writeResponse(requestId, msgBody)
Writes a new response into our managed output stream using the provided requestId
Parameters:
Name | Type | Description |
---|---|---|
requestId |
integer | The requestId being responded to |
msgBody |
string | The body of the response |
Type Definitions
responseCallback(responseMessage)
A callback invoked with a response message
Parameters:
Name | Type | Description |
---|---|---|
responseMessage |
string |
Events
request
Request event
Type:
Properties:
Name | Type | Description |
---|---|---|
0 |
integer | The requestId |
1 |
string | The request body |