Skip to content

Response.variables.readJsonWithStandardSchemaV1

fx-fetch


fx-fetch / Response / readJsonWithStandardSchemaV1

const readJsonWithStandardSchemaV1: {<A, I>(response, schema): Effect<A, MalformedJsonError | ParseError, never>; <A, I>(schema): (response) => Effect<A, MalformedJsonError | ParseError, never>; }

Defined in: packages/fx-fetch/src/Response/readJsonWithStandardSchemaV1.ts:81

Reads a JSON response with the given standard schema.

<A, I>(response, schema): Effect<A, MalformedJsonError | ParseError, never>

Reads a JSON response with the given standard schema.

A

I

Response

StandardSchemaV1<I, A>

Effect<A, MalformedJsonError | ParseError, never>

import { Response } from 'fx-fetch';
import { Effect } from 'effect';
import { z } from 'zod'; // Or any other schema library compatible with Standard Schema
const UserSchema = z.object({
name: z.string(),
age: z.number()
});
const response = Response.unsafeMake({
ok: true,
status: 200,
statusText: '200 OK',
type: 'default',
url: 'https://api.example.com',
body: '{"name":"Alice","age":25}'
});
const userEffect = Response.readJsonWithStandardSchemaV1(response, UserSchema);

https://standardschema.dev/schema

1.1.0

<A, I>(schema): (response) => Effect<A, MalformedJsonError | ParseError, never>

Reads a JSON response with the given standard schema.

A

I

StandardSchemaV1<I, A>

(response): Effect<A, MalformedJsonError | ParseError, never>

Response

Effect<A, MalformedJsonError | ParseError, never>

import { Response } from 'fx-fetch';
import { Effect, pipe } from 'effect';
import { z } from 'zod'; // Or any other schema library compatible with Standard Schema
const UserSchema = z.object({
name: z.string(),
age: z.number()
});
const response = Response.unsafeMake({
ok: true,
status: 200,
statusText: '200 OK',
type: 'default',
url: 'https://api.example.com',
body: '{"name":"Alice","age":25}'
});
const userEffect = pipe(
response,
Response.readJsonWithStandardSchemaV1(UserSchema)
);

https://standardschema.dev/schema

1.1.0

import { Response } from 'fx-fetch';
import { Effect } from 'effect';
import { z } from 'zod'; // Or any other schema library compatible with Standard Schema
const UserSchema = z.object({
name: z.string(),
age: z.number()
});
const response = Response.unsafeMake({
ok: true,
status: 200,
statusText: '200 OK',
type: 'default',
url: 'https://api.example.com',
body: '{"name":"Alice","age":25}'
});
// Data-first
const userEffect1 = Response.readJsonWithStandardSchemaV1(response, UserSchema);
// Data-last (pipeable)
const userEffect2 = pipe(
response,
Response.readJsonWithStandardSchemaV1(UserSchema)
);

https://standardschema.dev/schema

1.1.0