Inherits: IConfigurable, IReferenceable, IOpenable
Description
The HttpEndpoint class allows you to create HTTP endpoints.
Important points
- An endpoint is a URL at which a given service can be accessed by a client.
 
Configuration parameters
Parameters to pass to the configure method for component configuration:
- connection(s): the connection resolver’s connections:
- “connection.discovery_key”: key to use for connection resolving in a discovery service;
 - “connection.protocol”: connection’s protocol;
 - “connection.host”: target host;
 - “connection.port”: target port;
 - “connection.uri”: target URI.
 
 - credential: the HTTPS credentials:
- “credential.ssl_key_file”: SSL private key in PEM
 - “credential.ssl_crt_file”: SSL certificate in PEM
 - “credential.ssl_ca_file”: certificate authorities (root cerfiticates) in PEM
 
 
References
A logger, counters, and a connection resolver can be referenced by passing the following references to the object’s set_references method:
- *: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 connections
 
Instance methods
CloseAsync
Closes this endpoint and the REST server (service) that was opened earlier.
public virtualTask CloseAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
 
Configure
Configures this HttpEndpoint using the given configuration parameters.
public virtualvoid Configure(ConfigParams config)
- config: ConfigParams - configuration parameters, containing a “connection(s)” section.
 
Initialize
Initializes the HttpEndpoint object.
publicvoid Initialize(IInitializable initialization)
- initialization: IInitializable - List with initialization values.
 
Instrument
Adds instrumentation to log calls and measure call time. It returns a CounterTiming object that is used to end the time measurement.
protectedCounterTiming Instrument(string correlationId, string name)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
 - name: string - method name.
 - returns: CounterTiming - CounterTiming object to end the time measurement.
 
IsOpen
Checks if the component is open.
public virtualbool IsOpen()
- returns: bool - true if this endpoint is open with an actively listening REST server and false otherwise.
 
Register
Registers a registerable object for dynamic endpoint discovery.
publicvoid Register(IRegisterable registration)
- registration: IRegisterable - registration to add.
 
RegisterInterceptor
Registers a middleware action for the given route.
publicvoid RegisterInterceptor(string route, Func<HttpRequest, HttpResponse, ClaimsPrincipal, RouteData, Func<HttpRequest, HttpResponse, ClaimsPrincipal, RouteData, Task>, Task> action)
- route: string - route to register in this object’s REST server (service).
 - action: Func<HttpRequest, HttpResponse, ClaimsPrincipal, RouteData, Func<HttpRequest, HttpResponse, ClaimsPrincipal, RouteData, Task>, Task> - middleware action to perform at the given route.
 
RegisterRoute
Registers an action in this objects REST server (service) by the given method and route.
publicvoid RegisterRoute(string method, string route, Func<HttpRequest, HttpResponse, RouteData, Task> action)
- method: string - HTTP method of the route.
 - route: string - route to register in this object’s REST server (service).
 - action: Func<HttpRequest, HttpResponse, RouteData, Task> - action to perform at the given route.
 
RegisterRouteWithAuth
Registers an action with authorization in this objects REST server (service) by the given method and route.
publicvoid RegisterRouteWithAuth(string method, string route, Func<HttpRequest, HttpResponse, ClaimsPrincipal, RouteData, Func<Task>, Task> authorize, Func<HttpRequest, HttpResponse, ClaimsPrincipal, RouteData, Task> action)
- method: string - HTTP method of the route.
 - route: string - route to register in this object’s REST server (service).
 - authorize: Func<HttpRequest, HttpResponse, ClaimsPrincipal, RouteData, Func<Task>, Task> - authorization interceptor
 - action: Func<HttpRequest, HttpResponse, ClaimsPrincipal, RouteData, Task> - action to perform at the given route.
 
SetReferences
Sets references to this endpoint’s logger, counters, and connection resolver.
public virtualvoid SetReferences(IReferences references)
- references: IReferences - IReferences object, containing references to a logger, counters, and a connection resolver.
 
Uninitialize
Removes an initialization.
publicvoid Uninitialize(IInitializable initialization)
- initialization: IInitializable - initialization to remove.
 
Unregister
Unregisters a registerable object, so that it is no longer used in dynamic endpoint discovery.
publicvoid Unregister(IRegisterable registration)
- registration: IRegisterable - registration to remove.
 
Examples
public MyMethod(string correlationId, ConfigParams _config, IReferences _references) 
{
    var endpoint = new HttpEndpoint();
    if (this._config)
        endpoint.Configure(this._config);
    if (this._references)
        endpoint.SetReferences(this._references);
    ...
    this._endpoint.Open(correlationId);
    ...
}