1 | /** @module clients */
|
2 | import { RestClient } from './RestClient';
|
3 | /**
|
4 | * Abstract client that calls commandable HTTP service.
|
5 | *
|
6 | * Commandable services are generated automatically for [[https://pip-services3-node.github.io/pip-services3-commons-node/interfaces/commands.icommandable.html ICommandable objects]].
|
7 | * Each command is exposed as POST operation that receives all parameters
|
8 | * in body object.
|
9 | *
|
10 | * ### Configuration parameters ###
|
11 | *
|
12 | * base_route: base route for remote URI
|
13 | *
|
14 | * - connection(s):
|
15 | * - discovery_key: (optional) a key to retrieve the connection from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]]
|
16 | * - protocol: connection protocol: http or https
|
17 | * - host: host name or IP address
|
18 | * - port: port number
|
19 | * - uri: resource URI or connection string with all parameters in it
|
20 | * - options:
|
21 | * - retries: number of retries (default: 3)
|
22 | * - connect_timeout: connection timeout in milliseconds (default: 10 sec)
|
23 | * - timeout: invocation timeout in milliseconds (default: 10 sec)
|
24 | *
|
25 | * ### References ###
|
26 | *
|
27 | * - <code>\*:logger:\*:\*:1.0</code> (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/log.ilogger.html ILogger]] components to pass log messages
|
28 | * - <code>\*:counters:\*:\*:1.0</code> (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/count.icounters.html ICounters]] components to pass collected measurements
|
29 | * - <code>\*:discovery:\*:\*:1.0</code> (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connection
|
30 | *
|
31 | * ### Example ###
|
32 | *
|
33 | * class MyCommandableHttpClient extends CommandableHttpClient implements IMyClient {
|
34 | * ...
|
35 | *
|
36 | * public getData(correlationId: string, id: string,
|
37 | * callback: (err: any, result: MyData) => void): void {
|
38 | *
|
39 | * this.callCommand(
|
40 | * "get_data",
|
41 | * correlationId,
|
42 | * { id: id },
|
43 | * (err, result) => {
|
44 | * callback(err, result);
|
45 | * }
|
46 | * );
|
47 | * }
|
48 | * ...
|
49 | * }
|
50 | *
|
51 | * let client = new MyCommandableHttpClient();
|
52 | * client.configure(ConfigParams.fromTuples(
|
53 | * "connection.protocol", "http",
|
54 | * "connection.host", "localhost",
|
55 | * "connection.port", 8080
|
56 | * ));
|
57 | *
|
58 | * client.getData("123", "1", (err, result) => {
|
59 | * ...
|
60 | * });
|
61 | */
|
62 | export declare class CommandableHttpClient extends RestClient {
|
63 | /**
|
64 | * Creates a new instance of the client.
|
65 | *
|
66 | * @param baseRoute a base route for remote service.
|
67 | */
|
68 | constructor(baseRoute: string);
|
69 | /**
|
70 | * Calls a remote method via HTTP commadable protocol.
|
71 | * The call is made via POST operation and all parameters are sent in body object.
|
72 | * The complete route to remote method is defined as baseRoute + "/" + name.
|
73 | *
|
74 | * @param name a name of the command to call.
|
75 | * @param correlationId (optional) transaction id to trace execution through the call chain.
|
76 | * @param params command parameters.
|
77 | * @param callback callback function that receives result or error.
|
78 | */
|
79 | protected callCommand(name: string, correlationId: string, params: any, callback: (err: any, result: any) => void): void;
|
80 | }
|