RestService class Null safety

Abstract service that receives remove calls via HTTP/REST protocol.

Configuration parameters

  • base_route: base route for remote URI
  • dependencies:
    • endpoint: override for HTTP Endpoint dependency
    • controller: override for Controller dependency
  • connection:
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery
    • protocol: connection protocol: http or https
    • host: host name or IP address
    • port: port number
    • uri: resource URI or connection string with all parameters in it
  • credential - the HTTPS credentials:
    • ssl_key_file: the SSL private key in PEM
    • ssl_crt_file: the SSL certificate in PEM
    • ssl_ca_file: the certificate authorities (root cerfiticates) in PEM


  • \*: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 RestClient


class MyRestService extends RestService {
    IMyController _controller;
   MyRestService(): base() {

   void setReferences(references: IReferences) {
      _controller = dependencyResolver.getRequired<IMyController>('controller');

   void register() {
       registerRoute('get', 'get_mydata', null, (req, res)  {
           var correlationId = req.param('correlation_id');
           var id = req.param('id');
           var result = await _controller.getMyData(correlationId, id);
           sendResult(req,  null, result);

var service = MyRestService();
    'connection.protocol', 'http',
    '', 'localhost',
    'connection.port', 8080
   Descriptor('mygroup','controller','default','default','1.0'), controller

print('The REST service is running on port 8080');




baseRoute String?
The base route.
read / write
config ↔ ConfigParams?
read / write
counters ↔ CompositeCounters
The performance counters.
read / write
dependencyResolver ↔ DependencyResolver
The dependency resolver.
read / write
endpoint HttpEndpoint?
The HTTP endpoint that exposes this service.
read / write
hashCode int
The hash code for this object.
logger ↔ CompositeLogger
The logger.
read / write
runtimeType Type
A representation of the runtime type of the object.
swaggerEnable bool
read / write
swaggerRoute String
read / write
tracer ↔ CompositeTracer
read / write


close(String? correlationId) Future
Closes component and frees used resources.
configure(ConfigParams config) → void
Configures component by passing configuration parameters.
getCorrelationId(Request req) String?
Returns correlationId from request
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.
instrumentError(String? correlationId, String name, dynamic err, [bool? reerror = false]) → void
Adds instrumentation to error handling.
isOpen() bool
Checks if the component is opened.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
open(String? correlationId) Future
Opens the component.
register() → void
Registers all service routes in HTTP endpoint.
registerInterceptor(String route, dynamic action(Request req)) → void
Registers a middleware for a given route in HTTP endpoint.
registerOpenApiSpec_(String content) → void
registerOpenApiSpecFromFile(String path) → void
registerRoute(String method, String route, Schema? schema, FutureOr<Response> action(Request req)) → void
Registers a route in HTTP endpoint.
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.
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.
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.
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.
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.
setReferences(IReferences references) → void
Sets references to dependent components.
toString() String
A string representation of this object.
unsetReferences() → void
Unsets (clears) previously set references to dependent components.


operator ==(Object other) bool
The equality operator.