Package: @effect/cluster
Module: EntityProxy
Derives an HttpApiGroup from an Entity.
import { ClusterSchema, Entity, EntityProxy, EntityProxyServer } from "@effect/cluster"
import { HttpApi, HttpApiBuilder } from "@effect/platform"
import { Rpc } from "@effect/rpc"
import { Layer, Schema } from "effect"
export const Counter = Entity.make("Counter", [
Rpc.make("Increment", {
payload: { id: Schema.String, amount: Schema.Number },
primaryKey: ({ id }) => id,
success: Schema.Number
})
]).annotateRpcs(ClusterSchema.Persisted, true)
// Use EntityProxy.toHttpApiGroup to create a `HttpApiGroup` from the
// Counter entity
export class MyApi extends HttpApi.make("api")
.add(
EntityProxy.toHttpApiGroup("counter", Counter)
.prefix("/counter")
)
{}
// Use EntityProxyServer.layerHttpApi to create a layer that implements
// the handlers for the HttpApiGroup
const ApiLayer = HttpApiBuilder.api(MyApi).pipe(
Layer.provide(EntityProxyServer.layerHttpApi(MyApi, "counter", Counter))
)
Signature
declare const toHttpApiGroup: <const Name extends string, Type extends string, Rpcs extends Rpc.Any>(name: Name, entity: Entity.Entity<Type, Rpcs>) => HttpApiGroup.HttpApiGroup<Name, ConvertHttpApi<Rpcs>>
Since v1.0.0