#Mounting an Effect HTTP API

8 messages · Page 1 of 1 (latest)

austere plover
#

Hi, I'm wondering if anyone has tried to mount an Effect HTTP API within a TanStack Start server route? If so, I'd be greatly appreciative of any guidance!

#

Perhaps something like the following?:

import { HttpLayerRouter } from "@effect/platform"
import { createFileRoute } from "@tanstack/react-router"
import { ApiLive } from "~/api/ApiLive"

const { handler: webHandler } = HttpLayerRouter.toWebHandler(ApiLive)
const handler = ({ request }: { request: Request }) => webHandler(request)

export const Route = createFileRoute("/api/v1/$")({
  server: {
    handlers: {
      GET: handler,
      POST: handler,
      OPTIONS: handler,
      ALL: handler,
      HEAD: handler,
      DELETE: handler,
      PUT: handler,
      PATCH: handler,
    },
  },
})
pure leaf
#

you can also use ANY: handler

#

to forward... any method

austere plover
#

Thank you!

opaque acorn
#

@austere plover did that work? I have been thinking about trying the same

pure leaf
#

it should just work. if not please let us know

austere plover
#

I ended up switching to just Effect Platform for my back end + using TanStack router on the front end (not start)