Integrating Effect/RPC with Next.js and TanStack Query

Hello everyone!
I'm fairly new to effect and I am currently trying to integrate effect/rpc into NextJS and replacing tRPC while also integrating with TanStack Query. I'm sort of lacking some knowledge on how everything comes together and I'm currently stuck in grouping and identifying all my rpcs in order to serve in a single route /api/rpc. Does anyone have any repo or advice I can follow along to further improve this whole process?

This is my current /api/rpc/route.ts file.

import { TodosRpcs } from "@/lib/schemas/todos";
import { Layer } from "effect";
import { RpcSerialization, RpcServer } from "@effect/rpc";
import type { NextRequest } from "next/server";
import { HttpServer } from "@effect/platform";
import { TodosRouter } from "@/lib/routers/todos";

const handler = RpcServer.toWebHandler(TodosRpcs, {
  layer: Layer.mergeAll(
    TodosRouter,
    RpcSerialization.layerJson,
    HttpServer.layerContext
  ),
});

export const POST = async (req: NextRequest) => {
  return await handler.handler(req);
};
Was this page helpful?