Skip to content

Conversation

@floydspace
Copy link
Contributor

@floydspace floydspace commented Nov 8, 2025

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

My motivation is having an ability to define endpoint handlers as standalone functions, but this requires defining handler type explicitly, so the ExtractHandlerType can help with that, so it will infer what possible from HttpApi definitions

Examples:

const group1 = HttpApiGroup.make("Group1").add(
  HttpApiEndpoint.get("Endpoint1")`/`
)
const group2 = HttpApiGroup.make("Group2").add(
  HttpApiEndpoint.get("Endpoint2")`/`
)
const api = HttpApi.make("TestApi").add(group1).add(group2)

//      ┌─── | HttpApiGroup<"Group1", HttpApiEndpoint<"Endpoint1", "GET">, never>
//      |    | HttpApiGroup<"Group2", HttpApiEndpoint<"Endpoint2", "GET">, never>
//      ▼
type groups = HttpApi.HttpApi.Groups<typeof api>

//      ┌─── HttpApiEndpoint<"Endpoint1", "GET">
//      ▼
type endpoints = HttpApi.HttpApi.EndpointsWithGroupName<typeof api, "Group1">

//      ┌─── HttpApiEndpoint.Handler<HttpApiEndpoint<"Endpoint1", "GET">, never, never>
//      ▼
type handler = HttpApi.HttpApi.ExtractHandlerType<
  typeof api,
  "Group1",
  "Endpoint1",
  never,
  never
>

the end goal is smt like this

declare const listPersons: ExtractHandlerType<typeof ServiceApi, "persons", "listPersons", never, PersonStore>;

const personsGroup = HttpApiBuilder.group(ServiceApi, "persons", (handlers) =>
  handlers.handle("listPersons", listPersons)
);

Please review carefuly the parts where I narrowed down the string generics to the expected literals

Related

  • Related Issue #
  • Closes #

@floydspace floydspace requested a review from tim-smart as a code owner November 8, 2025 21:13
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Nov 8, 2025
@changeset-bot
Copy link

changeset-bot bot commented Nov 8, 2025

🦋 Changeset detected

Latest commit: 7d119f0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 31 packages
Name Type
@effect/platform Patch
@effect/cli Patch
@effect/cluster Patch
@effect/experimental Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/rpc Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-drizzle Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-node Patch
@effect/sql Patch
@effect/workflow Patch
@effect/ai Patch
@effect/ai-amazon-bedrock Patch
@effect/ai-anthropic Patch
@effect/ai-google Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/sql-kysely Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

1 participant