Effect CommunityEC
Effect Community2y ago
22 replies
Andres Sulbaran

Refactoring EnvConfig Integration into makeClient Function in TypeScript

Hi every one, i have a question here, how can i in this example move the EnvConfig to the makeClient (RPC) instead of passing the the string for the pretendUrl there is a better way to achieve that to avoid repeat much code?
// Create the client
const makeClient = (prentendUrl: string) =>
  HttpResolver.make<AuthMicroserviceRouter>(
    HttpClient.fetchOk.pipe(HttpClient.mapRequest(HttpClientRequest.prependUrl(prentendUrl))),
  ).pipe(Resolver.toClient)

export const findAllUsers = RouterBuilder.handler(UserApi, 'findAllUsers', ({ query: criteria }) =>
  pipe(
    EnvConfig,
    T.flatMap(({ authMicroserviceUrl }) => makeClient(authMicroserviceUrl)(new UserRpc.FindAllUsers({ criteria }))),
  ),
)
Was this page helpful?