T
TanStack2mo ago
genetic-orange

Mounting an Effect HTTP API

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!
6 Replies
genetic-orange
genetic-orangeOP2mo ago
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,
},
},
})
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,
},
},
})
inland-turquoise
inland-turquoise2mo ago
you can also use ANY: handler to forward... any method
genetic-orange
genetic-orangeOP2mo ago
Thank you!
rare-sapphire
rare-sapphire2mo ago
@harrysolovay did that work? I have been thinking about trying the same
inland-turquoise
inland-turquoise2mo ago
it should just work. if not please let us know
genetic-orange
genetic-orangeOP2mo ago
I ended up switching to just Effect Platform for my back end + using TanStack router on the front end (not start) I wasn't able to get it working. Sorry I can't weigh in more.

Did you find this page helpful?