@@ -0,0 +1,15 @@
|
||||
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"),
|
||||
})
|
||||
Reference in New Issue
Block a user