CommandableHttpService class abstract
Abstract service that receives remove calls via HTTP/REST protocol to operations automatically generated for commands defined in ICommandable components. Each command is exposed as POST operation that receives all parameters in body object.
Commandable services require only 3 lines of code to implement a robust external HTTP-based remote interface.
Configuration parameters
base_route
: base route for remote URIdependencies
:- endpoint: override for HTTP Endpoint dependency
controller
: override for Controller dependency
- connection:
discovery_key
: (optional) a key to retrieve the connection from IDiscoveryprotocol
: connection protocol: http or httpshost
: host name or IP addressport
: port numberuri
: resource URI or connection string with all parameters in it
References
\*:logger:\*:\*:1.0
(optional) ILogger components to pass log messages\*:counters:\*:\*:1.0
(optional) ICounters components to pass collected measurements\*:discovery:\*:\*:1.0
(optional) IDiscovery services to resolve connection\*:endpoint:http:\*:1.0
(optional) HttpEndpoint reference
See CommandableHttpClient See RestService
Example
class MyCommandableHttpService extends CommandableHttpService {
MyCommandableHttpService(): base() {
dependencyResolver.put(
"controller",
Descriptor("mygroup","controller","*","*","1.0")
);
}
}
var service = MyCommandableHttpService();
service.configure(ConfigParams.fromTuples([
"connection.protocol", "http",
"connection.host", "localhost",
"connection.port", 8080
]));
service.setReferences(References.fromTuples([
new Descriptor("mygroup","controller","default","default","1.0"), controller
]));
await service.open("123");
print("The REST service is running on port 8080");
- Inheritance
-
- Object
- RestService
- CommandableHttpService
Constructors
- CommandableHttpService(String baseRoute)
- Creates a new instance of the service.
Properties
- baseRoute ↔ String?
-
The base route.
getter/setter pairinherited
- config ↔ ConfigParams?
-
getter/setter pairinherited
- counters ↔ CompositeCounters
-
The performance counters.
getter/setter pairinherited
- dependencyResolver ↔ DependencyResolver
-
The dependency resolver.
getter/setter pairinherited
- endpoint ↔ HttpEndpoint?
-
The HTTP endpoint that exposes this service.
getter/setter pairinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- logger ↔ CompositeLogger
-
The logger.
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- swaggerAuto ↔ bool
-
getter/setter pair
- swaggerEnable ↔ bool
-
getter/setter pairinherited
- swaggerRoute ↔ String
-
getter/setter pairinherited
- tracer ↔ CompositeTracer
-
getter/setter pairinherited
Methods
-
close(
String? correlationId) → Future -
Closes component and frees used resources.
inherited
-
configure(
ConfigParams config) → void -
Configures component by passing configuration parameters.
override
-
getCorrelationId(
Request req) → String? -
Returns correlationId from request
inherited
-
instrument(
String? correlationId, String name) → InstrumentTiming -
Adds instrumentation to log calls and measure call time.
It returns a Timing object that is used to end the time measurement.
inherited
-
instrumentError(
String? correlationId, String name, dynamic err, [bool? reerror = false]) → void -
Adds instrumentation to error handling.
inherited
-
isOpen(
) → bool -
Checks if the component is opened.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
open(
String? correlationId) → Future -
Opens the component.
inherited
-
register(
) → void -
Registers all service routes in HTTP endpoint.
override
-
registerInterceptor(
String route, dynamic action(Request req)) → void -
Registers a middleware for a given route in HTTP endpoint.
inherited
-
registerOpenApiSpec_(
String content) → void -
inherited
-
registerOpenApiSpecFromFile(
String path) → void -
inherited
-
registerRoute(
String method, String route, Schema? schema, FutureOr< Response> action(Request req)) → void -
Registers a route in HTTP endpoint.
inherited
-
registerRouteWithAuth(
String method, String route, Schema schema, FutureOr< Response?> authorize(Request req, Future next()), FutureOr<Response> action(Request req)) → void -
Registers a route with authorization in HTTP endpoint.
inherited
-
sendCreatedResult(
Request req, dynamic result) → FutureOr< Response> -
Creates function that sends newly created object as JSON.
That function call be called directly or passed
as a parameter to business logic components.
inherited
-
sendDeletedResult(
Request req, dynamic result) → FutureOr< Response> -
Creates a function that sends deleted object as JSON.
That function call be called directly or passed
as a parameter to business logic components.
inherited
-
sendError(
Request req, dynamic error) → FutureOr< Response> -
Sends error serialized as ErrorDescription object
and appropriate HTTP status code.
If status code is not defined, it uses 500 status code.
inherited
-
sendResult(
Request req, dynamic result) → FutureOr< Response> -
Sends result as JSON object.
That function call be called directly or passed
as a parameter to business logic components.
inherited
-
setReferences(
IReferences references) → void -
Sets references to dependent components.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unsetReferences(
) → void -
Unsets (clears) previously set references to dependent components.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited