Effect CommunityEC
Effect Community2y ago
161 replies
Stephen Bluck

Understanding the Use of Http.router* in Web Development

This is going to be a dumb question but what is Http.router* used for? How does one use it and wire it up? I got this far:
const Login = Http.router
  .schemaSearchParams(S.struct({ a: S.string }))
  .pipe(Effect.flatMap((a) => Http.response.json({})));

const LoginRoute = Http.router.makeRoute("GET", "/login", Login);

const app = LoginRoute.handler.pipe(
  Effect.provideService(Http.router.RouteContext, { route: "??", params: {}, searchParams: {} }),
  Effect.provideService(Http.request.ServerRequest, Http.request.fromWeb(new Request(""))),
);

Once you have a Route (LoginRoute), what do you do with it?

More info (maybe unrelated)
I came across it as I was in need of parsing search params. I currently use Http.app.toWebHandler in my app but am wondering if I could instead create a better api which isn't tied to Remix and instead create a bunch of routes which my Remix app could interop with.
Was this page helpful?