Class: HttpClientFactory

HttpClientFactory

Creates instance of HttpClientFactory


new HttpClientFactory(options)

Additional parameters and properties ontop of those inherited from JsonRpcClientFactory

Parameters:
Name Type Description
options Object

Connection options for the factory class

Properties
Name Type Argument Default Description
encoding string <optional>
"utf-8"

Encoding to be used for the request

method string <optional>
"POST"

Type of request to make

headers object <optional>
{"Content-Type": "application/json", Accept: "application/json"}

Request headers

path string <optional>
"/"

URL path to make request to

Properties:
Name Type Description
headers object

Same as options.headers

encoding string

Same as options.encoding

scheme 'http' | 'https'

Scheme to make connection with

Source:

Extends

Methods


batch(requests)

Calls batch() method on protocol instance

Parameters:
Name Type Description
requests Array.<JSON>

Valid JSON-RPC batch request array

Inherited From:
Overrides:
Source:

<abstract> buildProtocol()

Set the pcolInstance for the client factory

Inherited From:
Overrides:
Source:
Example
this.pcolInstance = new JsonRpcClientProtocol()

cleanUp(ids)

Clears pending timeouts kept in timeouts property for the provided request IDs.

Parameters:
Name Type Description
ids Array.<string> | Array.<number>

Array of request IDs

Inherited From:
Overrides:
Source:

connect()

Calls buildProtocol method.

Calls connect() on protocol instance

Inherited From:
Overrides:
Source:

<abstract> end()

Calls end() on protocol instance

Inherited From:
Overrides:
Source:

message(method, params [, id])

Calls message() on the protocol instance

Parameters:
Name Type Argument Description
method string

Name of the method to use in the request

params Array | JSON

Params to send

id boolean <optional>

If true it will use instances message_id for the request id, if false will generate a notification request

Inherited From:
Overrides:
Source:
Example
client.message("hello", ["world"]) // returns {"jsonrpc": "2.0", "method": "hello", "params": ["world"], "id": 1}
client.message("hello", ["world"], false) // returns {"jsonrpc": "2.0", "method": "hello", "params": ["world"]}

notify(method, params)

Calls notify() method on protocol instance

Promise will resolve if the request was sucessfully sent, and reject if there was an error sending the request.

Parameters:
Name Type Description
method string

Name of the method to use in the notification

params Array | JSON

Params to send

Inherited From:
Overrides:
Source:
Returns:

Promise

Example
client.notify("hello", ["world"])

request()

Calls request() method on protocol instance

Plans to deprecate this in future versions.

Inherited From:
Overrides:
Source:

send(method, params)

Calls send() method on protocol instance

Promise will resolve when a response has been received for the request.

Promise will reject if the server responds with an error object, or if the response is not received within the set requestTimeout

Parameters:
Name Type Description
method string

Name of the method to use in the request

params Array | JSON

Params to send

Inherited From:
Overrides:
Source:
Returns:

Promise

Example
client.send("hello", {"foo": "bar"})

serverDisconnected(cb)

Listens for a serverDisconnected event, passing the callback function

Parameters:
Name Type Description
cb function
Inherited From:
Overrides:
Source:

<abstract> subscribe(method, cb)

Subscribe the function to the given event name

Parameters:
Name Type Description
method string

Method name to subscribe to

cb function

Name of callback function to invoke on event

Inherited From:
Overrides:
Source:

<abstract> unsubscribe(method, cb)

Unsubscribe the function from the given event name

Parameters:
Name Type Description
method string

Method to unsubscribe from

cb function

Name of function to remove

Inherited From:
Overrides:
Source:

<abstract> unsubscribeAll(method)

Unsubscribe all functions from given event name

Parameters:
Name Type Description
method string

Method to unsubscribe all listeners from

Inherited From:
Overrides:
Source: