Skip to content

Fetch.variables.fetchJsonWithSchema

fx-fetch


fx-fetch / Fetch / fetchJsonWithSchema

const fetchJsonWithSchema: {<A, I, R>(request, schema): Effect<A, MalformedJsonError | FetchError | AbortError | NotAllowedError | ParseError | NotOkError, Fetch | R>; <A, I, R>(schema): (request) => Effect<A, MalformedJsonError | FetchError | AbortError | NotAllowedError | ParseError | NotOkError, Fetch | R>; }

Defined in: packages/fx-fetch/src/Fetch/fetchJsonWithSchema.ts:49

Fetches and reads a JSON response with the given schema.

<A, I, R>(request, schema): Effect<A, MalformedJsonError | FetchError | AbortError | NotAllowedError | ParseError | NotOkError, Fetch | R>

Fetches and reads a JSON response with the given schema.

A

I

R

Request

Schema<A, I, R>

Effect<A, MalformedJsonError | FetchError | AbortError | NotAllowedError | ParseError | NotOkError, Fetch | R>

0.1.0

Response.readJsonWithSchema

import { Effect, Schema } from 'effect';
import { Fetch, Request, Response } from 'fx-fetch';
const UserSchema = Schema.Struct({
id: Schema.Int,
name: Schema.String,
});
// ┌─── Effect.Effect<
// │ void,
// │ | Fetch.FetchError
// │ | Fetch.AbortError
// │ | Fetch.NotAllowedError
// │ | Response.NotOkError
// │ | MalformedJsonError
// │ | ParseError,
// │ Fetch.Fetch
// │ >
// ▼
const program = Effect.gen(function* () {
const request = Request.unsafeMake({ url: './my-endpoint' });
// ┌─── typeof UserSchema.Type
// ▼
const payload = yield* Fetch.fetchJsonWithSchema(request, UserSchema);
});

<A, I, R>(schema): (request) => Effect<A, MalformedJsonError | FetchError | AbortError | NotAllowedError | ParseError | NotOkError, Fetch | R>

Fetches and reads a JSON response with the given schema.

A

I

R

Schema<A, I, R>

(request): Effect<A, MalformedJsonError | FetchError | AbortError | NotAllowedError | ParseError | NotOkError, Fetch | R>

Request

Effect<A, MalformedJsonError | FetchError | AbortError | NotAllowedError | ParseError | NotOkError, Fetch | R>

0.1.0

Response.readJsonWithSchema

import { Effect, Schema } from 'effect';
import { Fetch, Request, Response } from 'fx-fetch';
const UserSchema = Schema.Struct({
id: Schema.Int,
name: Schema.String,
});
// ┌─── Effect.Effect<
// │ void,
// │ | Fetch.FetchError
// │ | Fetch.AbortError
// │ | Fetch.NotAllowedError
// │ | Response.NotOkError
// │ | MalformedJsonError
// │ | ParseError,
// │ Fetch.Fetch
// │ >
// ▼
const program = Effect.gen(function* () {
const request = Request.unsafeMake({ url: './my-endpoint' });
// ┌─── typeof UserSchema.Type
// ▼
const payload = yield* Fetch.fetchJsonWithSchema(request, UserSchema);
});

0.1.0

Response.readJsonWithSchema

import { Effect, Schema } from 'effect';
import { Fetch, Request, Response } from 'fx-fetch';
const UserSchema = Schema.Struct({
id: Schema.Int,
name: Schema.String,
});
// ┌─── Effect.Effect<
// │ void,
// │ | Fetch.FetchError
// │ | Fetch.AbortError
// │ | Fetch.NotAllowedError
// │ | Response.NotOkError
// │ | MalformedJsonError
// │ | ParseError,
// │ Fetch.Fetch
// │ >
// ▼
const program = Effect.gen(function* () {
const request = Request.unsafeMake({ url: './my-endpoint' });
// ┌─── typeof UserSchema.Type
// ▼
const payload = yield* Fetch.fetchJsonWithSchema(request, UserSchema);
});