Skip to content

Commit b749f91

Browse files
refactor platform request example
1 parent 140eaf1 commit b749f91

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/+1/platform.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import {
22
FetchHttpClient,
33
HttpClient,
4+
HttpClientRequest,
45
HttpClientResponse,
56
} from "@effect/platform";
6-
import { Effect } from "effect";
7+
import { Effect, flow } from "effect";
78
import { Pokemon } from "../schemas";
89

9-
export const main = HttpClient.get(
10-
"https://pokeapi.co/api/v2/pokemon/squirtle"
11-
).pipe(
10+
export const main = Effect.gen(function* () {
11+
const baseClient = yield* HttpClient.HttpClient;
12+
const pokeApiClient = baseClient.pipe(
13+
HttpClient.mapRequest(
14+
flow(
15+
HttpClientRequest.acceptJson,
16+
HttpClientRequest.prependUrl("https://pokeapi.co/api/v2")
17+
)
18+
)
19+
);
20+
21+
return yield* pokeApiClient.get("/pokemon/squirtle");
22+
}).pipe(
1223
Effect.flatMap(HttpClientResponse.schemaBodyJson(Pokemon)),
1324
Effect.scoped,
1425
Effect.provide(FetchHttpClient.layer)

0 commit comments

Comments
 (0)