16 lines
377 B
TypeScript
16 lines
377 B
TypeScript
import { Effect } from "effect"
|
|
|
|
|
|
export interface Post {
|
|
readonly title: string
|
|
readonly body: string
|
|
}
|
|
|
|
export const fetchPost = (id: number) => Effect.tryPromise({
|
|
try: () =>
|
|
fetch(`https://jsonplaceholder.typicode.com/posts/${id}`)
|
|
.then(response => response.json() as Promise<Post>),
|
|
|
|
catch: () => new Error("Unable to fetch post"),
|
|
})
|