Creates a server handler for this RPC group.
This method generates a handler function suitable for use in server environments (such as HTTP endpoints or serverless functions) that can process incoming requests and route them to the appropriate implementation based on the registered RPC group.
The environment type required by the request implementations.
An object mapping request names to their implementation functions. Each implementation should match the signature expected by the corresponding request.
Configuration options for the RPC handler, such as environment injection, error handling, or custom response formatting.
A function that takes a globalThis.Request
and an optional Context
, and returns a Promise<Response>
.
import { helloRequests } from './requests';
import { HelloService } from './service';
import { RpcSerialization } from '@effect/rpc';
const handler = helloRequests.createServerHandler(
{
SayByeReq: ({ name }) => HelloService.sayBye(name),
SayHelloReq: ({ name }) => HelloService.sayHello(name),
},
{
serviceLayers: HelloService.Default,
serialization: RpcSerialization.layerNdjson,
},
);
// Use in a server route
export const POST = handler;
Gets a specific request by name.
It can be used to send it to the custom runtime to execute the request.
The name of the request to retrieve.
The payload to send with the request.
The response from the request.
Returns all request names available in this handler. This is useful for introspection or dynamic request handling.
Type representing a tagged handler with methods to access requests and perform RPC calls.
Since
0.8.0