Skip to content

@grest-ts/discovery

Base package for service discovery in grest-ts. Provides the abstract class, types, and locator key that all discovery implementations build on.

For a full overview of how discovery works and available implementations, see the Discovery guide.

Exports

GGDiscoveryClient (abstract class)

The base class all discovery implementations extend:

typescript
abstract class GGDiscoveryClient {
    readonly isLocal: boolean = false;

    abstract registerRoutes(registrations: GGServiceRegistration[]): void;
    abstract register(): Promise<void>;
    abstract unregister(): Promise<void>;
    abstract discoverApi(apiName: string): Promise<string>;
}
MethodPurpose
registerRoutes()Called when an HTTP server starts. Tells discovery what APIs this service provides.
register()Registers the service with the discovery backend.
unregister()Cleans up on shutdown.
discoverApi()Returns the full URL for a given API name. This is what clients call.

The isLocal flag indicates local development mode. When true, cloud resources (AWS SNS, etc.) should use local adapters instead.

GG_DISCOVERY (locator key)

typescript
const GG_DISCOVERY = new GGLocatorKey<GGDiscoveryClient>("GGDiscovery");

Service locator key for registering and accessing the active discovery client.

GGServiceRegistration (interface)

typescript
interface GGServiceRegistration {
    runtime: string;       // Service name
    api: string;           // API name, e.g. "UserApi"
    protocol: "http" | "ws";
    port: number;
    pathPrefix: string;    // e.g. "/api/users/"
}

Implementations

PackageUse case
@grest-ts/discovery-staticProduction deployments with known URLs
@grest-ts/discovery-localLocal development and testing
@grest-ts/discovery-kubernetesKubernetes deployments
@grest-ts/discovery-migrationZero-downtime migration between strategies