new HttpServerProtocol()
As well as all the params and properties in JsonRpcServerProtocol the following properties are available.
- Source:
Properties:
Name | Type | Default | Description |
---|---|---|---|
response |
class | HTTP response object |
|
headers |
object | {"Content-Type":"application/json"} | HTTP response headers |
Extends
Methods
-
clientConnected()
-
Registers the
event
data listener when client connects.Pushes received data into
messageBuffer
and calls _waitForData.The HTTP server does not use the delimiter since the completion of a request indicates the end of data.
- Overrides:
- Source:
-
getResult(message)
-
Get the result for the request. Calls the function associated with the method and returns the result.
Parameters:
Name Type Description message
JSON Valid JSON-RPC message object
- Inherited From:
- Overrides:
- Source:
Returns:
- Type
- Promise
-
gotBatchRequest(requests)
-
Attempts to get the result for all requests in the batch. Will send result to client if successful and error otherwise.
Parameters:
Name Type Description requests
Array.<JSON> Valid JSON-RPC batch request
- Inherited From:
- Overrides:
- Source:
Returns:
- Type
- Array.<Promise>
-
gotError(error)
-
Writes error to the client. Will send a JSON-RPC error object if the passed error cannot be parsed.
Parameters:
Name Type Description error
Error Error
object instance where the message should be a JSON-RPC message object- Inherited From:
- Overrides:
- Source:
-
gotNotification(message)
-
Calls
emit
on factory with the event name beingmessage.method
and the data beingmessage
.Responds to client with 204 status.
Parameters:
Name Type Description message
object JSON-RPC message object
- Overrides:
- Source:
-
gotRequest(message)
-
Attempts to get the result for the request object. Will send result to client if successful and will send an error otherwise.
Parameters:
Name Type Description message
JSON JSON-RPC message object
- Inherited From:
- Overrides:
- Source:
Returns:
- Type
- Promise
-
setResponseStatus(options)
-
Set response status code
Parameters:
Name Type Description options
object Properties
Name Type Description errorCode
number The JSON-RPC error code to lookup a corresponding status code for
status
number The HTTP status code (will override the errorCode)
notification
boolean Inidicate if setting header for notification (will override other options with 204 status)
- Source:
-
validateMessage(message)
-
Validates if there are any issues with the incoming request
Parameters:
Name Type Description message
JSON Valid JSON-RPC request object
- Inherited From:
- Overrides:
- Source:
Throws:
Will throw an error for any of the below reasons
Reason Type message is not an object Invalid Request the server does not have the required method Method Not Found the params are not an array or object Invalid Params the "jsonrpc" property was passed for a v1 server Invalid Request -
validateRequest(chunk)
-
Validate the request message
Parameters:
Name Type Description chunk
string - Inherited From:
- Overrides:
- Source:
Throws:
Will throw an error with a JSON-RPC error object if chunk cannot be parsed
Returns:
- Type
- JSON
-
writeToClient(message)
-
Send message to the client.
Parameters:
Name Type Description message
string Stringified JSON-RPC message object
- Overrides:
- Source: