Effect CommunityEC
Effect Communityβ€’3y agoβ€’
53 replies
thewilkybarkid

Customizing HttpClient in Effect: Using a Custom Fetch Instance and Environment

I'm looking at porting some (Node) fp-ts code to Effect, and it's great to see HttpClient is similar to how I'd be doing it. I see it uses globalThis.fetch, is it possible to pass in my own fetch instance instead? My fp-ts library had it in the environment (https://github.com/thewilkybarkid/fetch-fp-ts/blob/18e6ae2f395bf245c0210325ab1ad6e1ba6ef8df/src/index.ts#L69-L71), which allowed me to easily and safely use make-fetch-happen in production (for HTTP caching) and fetch-mock in tests. I also used it to adding things like HTTP request/response logging, timeouts etc (https://github.com/PREreview/prereview.org/blob/aa23343f3360327a04abc524849b499f6f4a6a70/src/fetch.ts); there might be more Effect-native ways of achieveing these though.
Was this page helpful?