github Effect-TS/effect @effect/rpc-http@0.37.0

latest releases: @effect/sql-sqlite-wasm@0.11.5, @effect/sql-sqlite-react-native@0.14.5, @effect/sql-sqlite-node@0.12.5...
3 days ago

Minor Changes

  • #3541 7041393 Thanks @tim-smart! - refactor /platform HttpClient

    HttpClient.fetch removed

    The HttpClient.fetch client implementation has been removed. Instead, you can
    access a HttpClient using the corresponding Context.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 methods

    Instead 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 removed

    The HttpClientResponse helpers that also supplied the Scope have been removed.

    Instead, you can use the HttpClientResponse methods directly, and explicitly
    add a Effect.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.

Patch Changes

Don't miss a new effect release

NewReleases is sending notifications on new releases.