Question about HttpServerResponse Design Decisions and Logging in Effect Typescript Library

I had a question about some of the design decisions related to the HttpServerResponse. Here is a minimal code snippet related to a health check endpoint on my API

First, here is the API group definition that happens in my core module

import { HttpApiEndpoint, HttpApiGroup } from "@effect/platform"
import { Schema } from "effect"

export const SchemaHealthy = Schema.Struct({ status: Schema.Literal("ok") })

export const HealthApiGroup = HttpApiGroup.make("health")
  .add(
    HttpApiEndpoint.get("healthz", "/healthz")
      .addSuccess(SchemaHealthy)
  )


Second, here is the server defining it's handler

typescript 

import { HttpApiBuilder, HttpMiddleware, HttpServerResponse } from "@effect/platform"
import { Api, HealthApi } from "@src/core"
import { Effect } from "effect"

export const HttpHealthLive = HttpApiBuilder.group(
  Api,
  "health",
  (handlers) =>
    handlers.handle(
      "healthz",
      // Works, type safe, but couldn't figure out how to disable logging
      // () => Effect.succeed({ status: "ok" })
      // Works, loses some type safety, disables logging
      () =>
        HttpServerResponse.schemaJson(HealthApi.SchemaHealthy)({ status: "ok" }).pipe(
          Effect.catchTag("HttpBodyError", () => Effect.dieMessage("Failed to serialize health endpoint response")),
          HttpMiddleware.withLoggerDisabled
        )
    )
)


My goal here was was to disable logging just for this endpoint while retaining middleware logging for the rest of my API. My original solution was simply having the handler be
() => Effect.succeed({ status: "ok" })
This was nice as it was type safe with respect to my API definition (i.e. { status: "invalid" }) would raise a type error.

(continued in comments as I don't have discord nitro lol)
Was this page helpful?