Effect CommunityEC
Effect Community10mo ago
7 replies
Janosch

Using HttpApi to Model and Validate External APIs

Is it a bad idea to model external APIs using HttpApi to get internal documentation (using Swagger) for them out of the box plus the typed HttpClient? Assuming the external api is not well documented / and it is advisable to check the data coming back from it

const ExternalAPI = HttpApi.make("ExternalAPI").add(
  HttpApiGroup.make("someGroup").add(
    HttpApiEndpoint.get("someEndpoint")`/`.addSuccess(Schema.String)
  )
)
// Implement the "Greetings" group
const GreetingsLive = HttpApiBuilder.group(ExternalAPI, "someGroup", (handlers) =>
  handlers.handle("someEndpoint", () => Effect.gen(function* () {
    // use a http client to call the actual third party API
  })
)

and then use it like
const client = yield* HttpApiClient.make(ExternalAPI, {
    baseUrl: "https://external-api"
  })
Was this page helpful?