Minor Changes
-
#3541
7041393
Thanks @tim-smart! - refactor /platform HttpClientHttpClient.fetch removed
The
HttpClient.fetch
client implementation has been removed. Instead, you can
access aHttpClient
using the correspondingContext.Tag
.import { FetchHttpClient, HttpClient } from "@effect/platform" import { Effect } from "effect" Effect.gen(function* () { const client = yield* HttpClient.HttpClient // make a get request yield* client.get("https://jsonplaceholder.typicode.com/todos/1") }).pipe( Effect.scoped, // the fetch client has been moved to the `FetchHttpClient` module Effect.provide(FetchHttpClient.layer) )
HttpClient
interface now uses methodsInstead of being a function that returns the response, the
HttpClient
interface now uses methods to make requests.Some shorthand methods have been added to the
HttpClient
interface to make
less complex requests easier.import { FetchHttpClient, HttpClient, HttpClientRequest } from "@effect/platform" import { Effect } from "effect" Effect.gen(function* () { const client = yield* HttpClient.HttpClient // make a get request yield* client.get("https://jsonplaceholder.typicode.com/todos/1") // make a post request yield* client.post("https://jsonplaceholder.typicode.com/todos") // execute a request instance yield* client.execute( HttpClientRequest.get("https://jsonplaceholder.typicode.com/todos/1") ) })
Scoped
HttpClientResponse
helpers removedThe
HttpClientResponse
helpers that also supplied theScope
have been removed.Instead, you can use the
HttpClientResponse
methods directly, and explicitly
add aEffect.scoped
to the pipeline.import { FetchHttpClient, HttpClient } from "@effect/platform" import { Effect } from "effect" Effect.gen(function* () { const client = yield* HttpClient.HttpClient yield* client.get("https://jsonplaceholder.typicode.com/todos/1").pipe( Effect.flatMap((response) => response.json), Effect.scoped // supply the `Scope` ) })
Some apis have been renamed
Including the
HttpClientRequest
body apis, which is to make them more
discoverable.