Skip to content

Commit

Permalink
update HttpClient accessor changeset (#3757)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Oct 8, 2024
1 parent 90ceeab commit 8a69754
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .changeset/tricky-ears-protect.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,34 @@
---

add HttpClient accessor apis

These apis allow you to easily send requests without first accessing the `HttpClient` service.

Below is an example of using the `get` accessor api to send a GET request:

```ts
import { FetchHttpClient, HttpClient } from "@effect/platform"
import { Effect } from "effect"

const program = HttpClient.get(
"https://jsonplaceholder.typicode.com/posts/1"
).pipe(
Effect.andThen((response) => response.json),
Effect.scoped,
Effect.provide(FetchHttpClient.layer)
)

Effect.runPromise(program)
/*
Output:
{
userId: 1,
id: 1,
title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
body: 'quia et suscipit\n' +
'suscipit recusandae consequuntur expedita et cum\n' +
'reprehenderit molestiae ut ut quas totam\n' +
'nostrum rerum est autem sunt rem eveniet architecto'
}
*/
```

0 comments on commit 8a69754

Please sign in to comment.