Making HTTP Client Requests Generic with `@effect/platform`

Hey again! Exploring the
@effect/platform
package we find this piece of code under "HTTP Client":
const getPostAndValidate = Http.request
  .get('https://jsonplaceholder.typicode.com/posts/1')
  .pipe(
    Http.client.fetch(),
    Effect.andThen(
      Http.response.schemaBodyJson(Post),
    ),
    Effect.scoped,
  );

Where Post is defined as.
class Post extends Schema.Class<Post>('Post')({
  id: Schema.number,
  title: Schema.string,
}) {}

I'm wondering whether it is possible to make the above code generic, so instead of Post we use a generic type for code reuse, as getPostAndValidate represents a pretty common flow for fetching a typed data object.
The function signature would maybe look something like the below, however I cannot figure out what the generic constraint should be:
function getAndValidate<T extends Schema.Class>(schema: T, url: string) {
 // Implementation here...
}

Thanks for your help!
Was this page helpful?