Effect CommunityEC
Effect Community13mo ago
5 replies
disgruntleddev

Accessing Request Body when creating an API with Effect

I'm attempting to create an api similar to what I'd do with express and I'm quite lost on how I'd access the request body for incoming requests

here, is a snippet of the code

const router = HttpRouter.empty.pipe(
    HttpRouter.post(
        "/oauthredirect",
        Effect.gen(function* () {
            return yield* HttpServerResponse.json({
                foo: "bar",
            });
        }),
    ),
);

const App = router.pipe(
    Effect.annotateLogs({
        service: "oauth-redirect-server",
    }),
    HttpServer.serve(),
);

const Live = Layer.unwrapEffect(
    Effect.gen(function* () {
        yield* Effect.logInfo("Starting OAuth Redirect Server");

        return NodeHttpServer.layer(createServer, {
            port: 42069,
            host: "127.0.0.1",
        });
    }),
);


If anyone has any idea it'll be much appreciated
Was this page helpful?