import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, HttpServer } from "@effect/platform";
import { Effect, Layer, Schema } from "effect";
/**
* API
*/
class PingGroup extends HttpApiGroup.make("ping")
.add(
HttpApiEndpoint.get("ping", "/ping")
.addSuccess(Schema.Struct({ message: Schema.String })
)
) { }
class NestedApi extends HttpApi.make("nested-api")
.add(PingGroup)
.prefix("/nested") {
}
export class RootApi extends HttpApi.make("root-api")
.addHttpApi(NestedApi) {
}
/**
* Life Implementation
*/
const PingGroupLive = HttpApiBuilder
.group(NestedApi, "ping", (handlers) =>
handlers
.handle("ping", () => Effect.succeed({ message: "pong" }))
);
// const PingGroupLive2 = HttpApiBuilder
// .group(RootApi, "ping", (handlers) =>
// handlers
// .handle("ping", () => Effect.succeed({ message: "pong" }))
// );
const NestedApiLive = HttpApiBuilder
.api(NestedApi)
.pipe(Layer.provide(PingGroupLive))
const RootApiLive = HttpApiBuilder
.api(RootApi)
.pipe(Layer.provide(Layer.mergeAll(
NestedApiLive,
// PingGroupLive2
)))
const { handler } = HttpApiBuilder.toWebHandler(
Layer.mergeAll(
RootApiLive,
HttpServer.layerContext
)
)
/**
* Do stuff with the handler
*/
export const effectAPI = onRequest(
async (req, res) => {
const response = await handler(request);
res.send(await response.json())
});
import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, HttpServer } from "@effect/platform";
import { Effect, Layer, Schema } from "effect";
/**
* API
*/
class PingGroup extends HttpApiGroup.make("ping")
.add(
HttpApiEndpoint.get("ping", "/ping")
.addSuccess(Schema.Struct({ message: Schema.String })
)
) { }
class NestedApi extends HttpApi.make("nested-api")
.add(PingGroup)
.prefix("/nested") {
}
export class RootApi extends HttpApi.make("root-api")
.addHttpApi(NestedApi) {
}
/**
* Life Implementation
*/
const PingGroupLive = HttpApiBuilder
.group(NestedApi, "ping", (handlers) =>
handlers
.handle("ping", () => Effect.succeed({ message: "pong" }))
);
// const PingGroupLive2 = HttpApiBuilder
// .group(RootApi, "ping", (handlers) =>
// handlers
// .handle("ping", () => Effect.succeed({ message: "pong" }))
// );
const NestedApiLive = HttpApiBuilder
.api(NestedApi)
.pipe(Layer.provide(PingGroupLive))
const RootApiLive = HttpApiBuilder
.api(RootApi)
.pipe(Layer.provide(Layer.mergeAll(
NestedApiLive,
// PingGroupLive2
)))
const { handler } = HttpApiBuilder.toWebHandler(
Layer.mergeAll(
RootApiLive,
HttpServer.layerContext
)
)
/**
* Do stuff with the handler
*/
export const effectAPI = onRequest(
async (req, res) => {
const response = await handler(request);
res.send(await response.json())
});