Skip to content
Effect Days 2026 Get your ticket

RpcServer

27 exports Added in v1.0.0 Source

Constructors

toWebHandler

Added in v1.0.0 Source

Construct an http web handler from an RpcGroup.

Signature

declare function toWebHandler<Rpcs extends Any, LE>(group: RpcGroup<Rpcs>, options: {
readonly disableFatalDefects?: boolean;
readonly disableTracing?: boolean;
readonly layer: Layer<any, LE>;
readonly memoMap?: MemoMap;
readonly middleware?: (httpApp: Default) => Default<never, DefaultServices>;
readonly spanAttributes?: Record<string, unknown>;
readonly spanPrefix?: string;
}): {
readonly dispose: () => Promise<void>;
readonly handler: (request: Request, context?: Context<never>) => Promise<Response>;
}

Http App

toHttpApp

Added in v1.0.0 Source

Signature

declare const toHttpApp: <Rpcs extends Rpc.Any>(group: RpcGroup.RpcGroup<Rpcs>, options?: {
readonly disableFatalDefects?: boolean;
readonly disableTracing?: boolean;
readonly spanAttributes?: Record<string, unknown>;
readonly spanPrefix?: string;
}) => Effect.Effect<HttpApp.Default<never, Scope.Scope>, never, Scope.Scope | RpcSerialization.RpcSerialization | Rpc.ToHandler<Rpcs> | Rpc.Context<Rpcs> | Rpc.Middleware<Rpcs>>

Signature

declare const toHttpAppWebsocket: <Rpcs extends Rpc.Any>(group: RpcGroup.RpcGroup<Rpcs>, options?: {
readonly disableFatalDefects?: boolean;
readonly disableTracing?: boolean;
readonly spanAttributes?: Record<string, unknown>;
readonly spanPrefix?: string;
}) => Effect.Effect<HttpApp.Default<never, Scope.Scope>, never, Scope.Scope | RpcSerialization.RpcSerialization | Rpc.ToHandler<Rpcs> | Rpc.Context<Rpcs> | Rpc.Middleware<Rpcs>>

Interruption

Fiber id used for client interruptions.

Signature

declare const fiberIdClientInterrupt: Runtime

Fiber id used for transient interruptions.

Signature

declare const fiberIdTransientInterrupt: Runtime

Protocol

Create a RPC server that registers a HTTP route with a HttpLayerRouter.

It defaults to using websockets for communication, but can be configured to use HTTP.

Signature

declare function layerHttpRouter<Rpcs extends Any>(options: {
readonly concurrency?: number | "unbounded";
readonly disableFatalDefects?: boolean;
readonly disableTracing?: boolean;
readonly group: RpcGroup<Rpcs>;
readonly path: PathInput;
readonly protocol?: "http" | "websocket";
readonly spanAttributes?: Record<string, unknown>;
readonly spanPrefix?: string;
}): Layer<never, never, any>

A rpc protocol that uses streaming http for communication.

Signature

declare function layerProtocolHttp<I = Default>(options: {
readonly path: PathInput;
readonly routerTag?: any;
}): Layer<Protocol, never, RpcSerialization>

A rpc protocol that uses streaming http for communication.

Uses a HttpLayerRouter to provide the http endpoint.

Signature

declare function layerProtocolHttpRouter(options: {
readonly path: PathInput;
}): Layer<Protocol, never, any>

A rpc protocol that uses SocketServer for communication.

Signature

declare const layerProtocolSocketServer: Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization | SocketServer.SocketServer>

Create a protocol that uses the provided Stream and Sink for communication.

Signature

declare function layerProtocolStdio<EIn, EOut, RIn, ROut>(options: {
readonly stdin: Stream<Uint8Array<ArrayBufferLike>, EIn, RIn>;
readonly stdout: Sink<void, string | Uint8Array<ArrayBufferLike>, unknown, EOut, ROut>;
}): Layer<Protocol, never, RpcSerialization | RIn | ROut>

A rpc protocol that uses websockets for communication.

Signature

declare function layerProtocolWebsocket<I = Default>(options: {
readonly path: PathInput;
readonly routerTag?: any;
}): Layer<Protocol, never, RpcSerialization>

A rpc protocol that uses websockets for communication.

Uses a HttpLayerRouter to provide the websocket endpoint.

Signature

declare function layerProtocolWebsocketRouter(options: {
readonly path: PathInput;
}): Layer<Protocol, never, any>

Signature

declare const layerProtocolWorkerRunner: Layer.Layer<Protocol, WorkerError, WorkerRunner.PlatformRunner>

Signature

declare const makeProtocolHttp: <I = Default>(...args: [options: {
readonly path: PathInput;
readonly routerTag?: any;
}]) => Effect<any, unknown, unknown>

Signature

declare const makeProtocolHttpRouter: (...args: [options: {
readonly path: PathInput;
}]) => Effect<any, unknown, unknown>

Signature

declare const makeProtocolSocketServer: Effect<any, unknown, unknown>

Create a protocol that uses the provided Stream and Sink for communication.

Signature

declare const makeProtocolStdio: <EIn, EOut, RIn, ROut>(...args: [options: {
readonly stdin: Stream<Uint8Array<ArrayBufferLike>, EIn, RIn>;
readonly stdout: Sink<void, string | Uint8Array<ArrayBufferLike>, unknown, EOut, ROut>;
}]) => Effect<any, unknown, unknown>

Signature

declare const makeProtocolWebsocket: <I = HttpRouter.Default>(options: {
readonly path: HttpRouter.PathInput;
readonly routerTag?: Context.Tag<I, HttpRouter.HttpRouter.Service<any, any>>;
}) => Effect.Effect<Protocol["Type"], never, RpcSerialization.RpcSerialization | I>

Signature

declare const makeProtocolWebsocketRouter: (options: {
readonly path: HttpRouter.PathInput;
}) => Effect.Effect<Protocol["Type"], never, RpcSerialization.RpcSerialization | HttpLayerRouter.HttpRouter>

Signature

declare const makeProtocolWithHttpApp: Effect.Effect<{
readonly httpApp: HttpApp.Default<never, Scope.Scope>;
readonly protocol: Protocol["Type"];
}, never, RpcSerialization.RpcSerialization>

Signature

declare const makeProtocolWithHttpAppWebsocket: Effect.Effect<{
readonly httpApp: HttpApp.Default<never, Scope.Scope>;
readonly protocol: Protocol["Type"];
}, never, RpcSerialization.RpcSerialization>

Signature

declare const makeProtocolWorkerRunner: Effect.Effect<Protocol["Type"], WorkerError, WorkerRunner.PlatformRunner | Scope.Scope>

Protocol

Added in v1.0.0 Source

Signature

declare class Protocol extends any {
constructor();
static make: <EX, RX>(f: (write: any) => Effect<Omit<any, "run">, EX, RX>) => Effect<any, EX, RX>;
}

Server

layer

Added in v1.0.0 Source

Signature

declare function layer<Rpcs extends Any>(group: RpcGroup<Rpcs>, options?: {
readonly concurrency?: number | "unbounded";
readonly disableFatalDefects?: boolean;
readonly disableTracing?: boolean;
readonly spanAttributes?: Record<string, unknown>;
readonly spanPrefix?: string;
}): Layer<never, never, Protocol | ToHandler<Rpcs> | Context<Rpcs> | Middleware<Rpcs>>

make

Added in v1.0.0 Source

Signature

declare const make: <Rpcs extends Rpc.Any>(group: RpcGroup.RpcGroup<Rpcs>, options?: {
readonly concurrency?: number | "unbounded";
readonly disableFatalDefects?: boolean;
readonly disableTracing?: boolean;
readonly spanAttributes?: Record<string, unknown>;
readonly spanPrefix?: string;
}) => Effect.Effect<never, never, Protocol | Rpc.ToHandler<Rpcs> | Rpc.Middleware<Rpcs> | Rpc.Context<Rpcs>>

Signature

declare const makeNoSerialization: <Rpcs extends Rpc.Any>(group: RpcGroup.RpcGroup<Rpcs>, options: {
readonly concurrency?: number | "unbounded";
readonly disableClientAcks?: boolean;
readonly disableFatalDefects?: boolean;
readonly disableSpanPropagation?: boolean;
readonly disableTracing?: boolean;
readonly onFromServer: (response: FromServer<Rpcs>) => Effect.Effect<void>;
readonly spanAttributes?: Record<string, unknown>;
readonly spanPrefix?: string;
}) => Effect.Effect<RpcServer<Rpcs>, never, Rpc.ToHandler<Rpcs> | Rpc.Middleware<Rpcs> | Scope.Scope>

RpcServer interface

Added in v1.0.0 Source

Signature

interface RpcServer<A extends Rpc.Any> {
readonly disconnect: (clientId: number) => Effect<void>;
readonly write: (clientId: number, message: FromClient<A>) => Effect<void>;
}