HttpApiServer class
A reusable, versioned REST API in front of an OmnyServerHub.
Everything the CLI can do is reachable here too. Routes live under
/api/v1; /metrics (Prometheus) and /healthz sit at the root. A bearer
apiToken, when configured, is required for /api/v1 routes; request bodies
are validated and failures return structured JSON errors.
The API is a set of omnyhub Services. start hosts them on their own
OmnyHub (the standalone deployment); buildServices hands them over to be
mounted on an existing hub instead, so the REST API and the node control
channel can share one port.
Constructors
- HttpApiServer({required OmnyServerHub hub, String? apiToken, EventAggregator? events, HubMetrics? metrics, Object host = '0.0.0.0', int port = 8080, SecurityContext? securityContext, Duration eventKeepAlive = const Duration(seconds: 15)})
- Creates an API server.
Properties
- apiToken → String?
-
Optional bearer token required on
/api/v1requests.final - boundPort → int
-
The bound port (valid after start).
no setter
- eventKeepAlive → Duration
-
How often an idle event stream sends a keep-alive comment.
final
- events → EventAggregator?
-
Optional event aggregator powering
/api/v1/events.final - hashCode → int
-
The hash code for this object.
no setterinherited
- host → Object
-
The bind host.
final
- hub → OmnyServerHub
-
The Hub this API fronts.
final
- metrics → HubMetrics?
-
Optional metrics powering
/metrics.final - port → int
-
The bind port (0 for ephemeral).
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- securityContext → SecurityContext?
-
Optional TLS context (plaintext when null).
final
Methods
-
buildMiddleware(
) → List< Middleware> - The middleware this API needs, outermost first.
-
buildServices(
) → List< Service> -
The omnyhub services this API exposes: the authenticated
/api/v1surface, the unauthenticated root endpoints, and the OpenAPI document. -
close(
) → Future< void> - Stops the server, hanging up any live streams first.
-
corsMiddleware(
) → Middleware? -
The CORS middleware for the Hub's allowed origins, or
nullwhen none are configured (no browser client, nothing to allow). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
start(
) → Future< void> -
Starts a standalone
OmnyHubhosting the API on host:port. -
tokenAuthenticator(
) → Authenticator -
The authenticator guarding
/api/v1. Nevernull: the Hub is controlled only with the apiToken or a grant's(principal, token)pair, so an unauthenticated caller is refused whether or not an apiToken is set. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
isAnyOrigin(
String origin) → bool -
Whether
originis the wildcard, tolerating the surrounding whitespace a shell or an env-var passthrough can leave behind.
Constants
- anyOrigin → const String
-
The wildcard origin:
--cors-origin '*'means "any origin". - apiServiceName → const String
-
The name of the token-gated
/api/v1service.