import { NodeRuntime } from "@effect/platform-node";
import * as Http from "@effect/platform/HttpClient";
import { Schema } from "@effect/schema";
import { Console, Effect } from "effect";
const Post = Schema.struct({
id: Schema.number,
title: Schema.string,
});
/*
const getPostAndValidate: Effect.Effect<{
readonly id: number;
readonly title: string;
}, Http.error.HttpClientError | ParseError, never>
*/
const getPostAndValidate = Http.request
.get("https://jsonplaceholder.typicode.com/posts/1")
.pipe(
Http.client.fetch,
Effect.andThen(Http.response.schemaBodyJson(Post)),
Effect.scoped
);
NodeRuntime.runMain(getPostAndValidate.pipe(Effect.andThen(Console.log)));
/*
Output:
{
id: 1,
title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit'
}
*/
import { NodeRuntime } from "@effect/platform-node";
import * as Http from "@effect/platform/HttpClient";
import { Schema } from "@effect/schema";
import { Console, Effect } from "effect";
const Post = Schema.struct({
id: Schema.number,
title: Schema.string,
});
/*
const getPostAndValidate: Effect.Effect<{
readonly id: number;
readonly title: string;
}, Http.error.HttpClientError | ParseError, never>
*/
const getPostAndValidate = Http.request
.get("https://jsonplaceholder.typicode.com/posts/1")
.pipe(
Http.client.fetch,
Effect.andThen(Http.response.schemaBodyJson(Post)),
Effect.scoped
);
NodeRuntime.runMain(getPostAndValidate.pipe(Effect.andThen(Console.log)));
/*
Output:
{
id: 1,
title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit'
}
*/