effect-rpc
    Preparing search index...

    Function getServerLayers

    • Constructs and returns a merged Layer composed of several essential server-side layers, along with any additional layers provided as arguments.

      This function is typically used to assemble the foundational infrastructure required for server-side effectful RPC (Remote Procedure Call) operations. It merges the following layers by default:

      • RpcSerialization.layerNdjson: Provides NDJSON-based serialization for RPC communication.
      • FetchHttpClient.layer: Supplies an HTTP client implementation based on the Fetch API.
      • HttpServer.layerContext: Sets up the HTTP server context required for handling requests.
      • Any additional layers passed via the additionalLayers parameter.

      You can customize the following aspects:

      • The serialization layer used for RPC communication by providing a custom serialization property. Must be of type SerializationLayer.

      You should use these when you want to handle the RPC endpoints in Next.js Route Handlers.

      NOTE: If you use a custom serialization layer, make sure it is compatible with the RPC server you are communicating with. This means, you most likely want to modify the createEffectRPC function invocation to use the same serialization layer!

      Parameters

      • config: {
            additionalLayers?: Layer<any, any, never>[];
            serialization?: SerializationLayer;
        } = ...

        Configuration object for the server layers.

        • OptionaladditionalLayers?: Layer<any, any, never>[]

          An optional list of additional Layer instances to be merged with the default server layers. For example, you might want to pass a custom live implementation of a middleware.

        • Optionalserialization?: SerializationLayer

      Returns Layer<any, any, never>

      A single Layer instance representing the merged server infrastructure.

      const serverLayers = getServerLayers(MyCustomLayer);
      
      const authMiddlewareLayer = AuthMiddleware.Default;
      const serverLayers = getServerLayers(authMiddlewareLayer, Layer.succeed(authMiddlewareLayer));
      // With a custom serialization layer
      import { RpcSerialization } from "@effect/rpc";
      const serverLayers = getServerLayers(authMiddlewareLayer, Layer.succeed(authMiddlewareLayer));

      0.3.0