UNPKG

3.59 kBTypeScriptView Raw
1import { ConfigParams } from 'pip-services3-commons-node';
2import { CommandSet } from 'pip-services3-commons-node';
3import { RestService } from './RestService';
4/**
5 * Abstract service that receives remove calls via HTTP protocol
6 * to operations automatically generated for commands defined in [[https://pip-services3-node.github.io/pip-services3-commons-node/interfaces/commands.icommandable.html ICommandable components]].
7 * Each command is exposed as POST operation that receives all parameters in body object.
8 *
9 * Commandable services require only 3 lines of code to implement a robust external
10 * HTTP-based remote interface.
11 *
12 * ### Configuration parameters ###
13 *
14 * - base_route: base route for remote URI
15 * - dependencies:
16 * - endpoint: override for HTTP Endpoint dependency
17 * - controller: override for Controller dependency
18 * - connection(s):
19 * - 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]]
20 * - protocol: connection protocol: http or https
21 * - host: host name or IP address
22 * - port: port number
23 * - uri: resource URI or connection string with all parameters in it
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 * - <code>\*:endpoint:http:\*:1.0</code> (optional) [[HttpEndpoint]] reference
31 *
32 * @see [[CommandableHttpClient]]
33 * @see [[RestService]]
34 *
35 * ### Example ###
36 *
37 * class MyCommandableHttpService extends CommandableHttpService {
38 * public constructor() {
39 * base();
40 * this._dependencyResolver.put(
41 * "controller",
42 * new Descriptor("mygroup","controller","*","*","1.0")
43 * );
44 * }
45 * }
46 *
47 * let service = new MyCommandableHttpService();
48 * service.configure(ConfigParams.fromTuples(
49 * "connection.protocol", "http",
50 * "connection.host", "localhost",
51 * "connection.port", 8080
52 * ));
53 * service.setReferences(References.fromTuples(
54 * new Descriptor("mygroup","controller","default","default","1.0"), controller
55 * ));
56 *
57 * service.open("123", (err) => {
58 * console.log("The REST service is running on port 8080");
59 * });
60 */
61export declare abstract class CommandableHttpService extends RestService {
62 protected _commandSet: CommandSet;
63 protected _swaggerAuto: boolean;
64 /**
65 * Creates a new instance of the service.
66 *
67 * @param baseRoute a service base route.
68 */
69 constructor(baseRoute: string);
70 /**
71 * Configures component by passing configuration parameters.
72 *
73 * @param config configuration parameters to be set.
74 */
75 configure(config: ConfigParams): void;
76 /**
77 * Registers all service routes in HTTP endpoint.
78 */
79 register(): void;
80}