The Accessor API provides a shortcut that skips the manual service access step.
Instead of writing yield* HttpClient.HttpClient first, you call the method directly on the HttpClient module:
import { FetchHttpClient, HttpClient } from "effect/unstable/http";import { Effect } from "effect";
function fetchUser(userId: number) { // Using accessor API. No need for Effect.gen to access the client return HttpClient.get(`https://dummyjson.com/users/${userId}`).pipe( Effect.andThen((response) => response.json), Effect.provide(FetchHttpClient.layer), );}
// Test itEffect.runPromise(fetchUser(2)).then((user) => { console.log("Name:", user.firstName, user.lastName);});Output:
Name: Michael Williams