MCPcopy Create free account
hub / github.com/Effect-TS/effect / endpoint

Function endpoint

packages/effect/src/unstable/httpapi/HttpApiClient.ts:596–629  ·  view source on GitHub ↗
(
  api: HttpApi.HttpApi<ApiId, Groups>,
  options: {
    readonly group: GroupIdentifier
    readonly endpoint: EndpointIdentifier
    readonly httpClient: HttpClient.HttpClient.With<E, R>
    readonly transformClient?:
      | ((client: HttpClient.HttpClient.With<E, R>) => HttpClient.HttpClient.With<E, R>)
      | undefined
    readonly transformResponse?:
      | ((effect: Effect.Effect<unknown, unknown, unknown>) => Effect.Effect<unknown, unknown, unknown>)
      | undefined
    readonly baseUrl?: URL | string | undefined
  }
)

Source from the content-addressed store, hash-verified

594 * @since 4.0.0
595 */
596export const endpoint = <
597 ApiId extends string,
598 Groups extends HttpApiGroup.Constraint,
599 const GroupIdentifier extends HttpApiGroup.Identifier<Groups>,
600 const EndpointIdentifier extends HttpApiGroup.EndpointsWithIdentifier<Groups, GroupIdentifier>["identifier"],
601 E,
602 R
603>(
604 api: HttpApi.HttpApi<ApiId, Groups>,
605 options: {
606 readonly group: GroupIdentifier
607 readonly endpoint: EndpointIdentifier
608 readonly httpClient: HttpClient.HttpClient.With<E, R>
609 readonly transformClient?:
610 | ((client: HttpClient.HttpClient.With<E, R>) => HttpClient.HttpClient.With<E, R>)
611 | undefined
612 readonly transformResponse?:
613 | ((effect: Effect.Effect<unknown, unknown, unknown>) => Effect.Effect<unknown, unknown, unknown>)
614 | undefined
615 readonly baseUrl?: URL | string | undefined
616 }
617): EndpointReturn<Groups, GroupIdentifier, EndpointIdentifier, E, R> => {
618 let client: any = undefined
619 return makeClient(api, {
620 ...options,
621 httpClient: options.transformClient
622 ? options.transformClient(options.httpClient)
623 : options.httpClient,
624 predicate: ({ endpoint, group }) => group.identifier === options.group && endpoint.identifier === options.endpoint,
625 onEndpoint({ endpointFn }) {
626 client = endpointFn
627 }
628 }).pipe(Effect.map(() => client)) as any
629}
630
631/**
632 * Creates a type-safe URL builder that mirrors `HttpApiClient.make`.

Callers

nothing calls this directly

Calls 3

makeClientFunction · 0.70
pipeMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected