Skip to content

Fetch.functions.fetchJson

fx-fetch


fx-fetch / Fetch / fetchJson

fetchJson(request): Effect<unknown, MalformedJsonError | FetchError | AbortError | NotAllowedError | NotOkError, Fetch>

Defined in: packages/fx-fetch/src/Fetch/fetchJson.ts:36

Fetches and reads a JSON response.

Request

Effect<unknown, MalformedJsonError | FetchError | AbortError | NotAllowedError | NotOkError, Fetch>

0.1.0

Response.readJson

import { Effect } from 'effect';
import { Fetch, Request, Response } from 'fx-fetch';
// ┌─── Effect.Effect<
// │ void,
// │ | Fetch.FetchError
// │ | Fetch.AbortError
// │ | Fetch.NotAllowedError
// │ | Response.NotOkError
// │ | MalformedJsonError,
// │ Fetch.Fetch
// │ >
// ▼
const program = Effect.gen(function* () {
const request = Request.unsafeMake({ url: './my-endpoint' });
// ┌─── unknown
// ▼
const payload = yield* Fetch.fetchJson(request);
});