Fetch.variables.fetchJsonWithSchema
fx-fetch / Fetch / fetchJsonWithSchema
Variable: fetchJsonWithSchema()
Section titled “Variable: fetchJsonWithSchema()”
constfetchJsonWithSchema: {<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.
Call Signature
Section titled “Call Signature”<
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.
Type Parameters
Section titled “Type Parameters”A
I
R
Parameters
Section titled “Parameters”request
Section titled “request”schema
Section titled “schema”Schema<A, I, R>
Returns
Section titled “Returns”Effect<A, MalformedJsonError | FetchError | AbortError | NotAllowedError | ParseError | NotOkError, Fetch | R>
0.1.0
Example
Section titled “Example”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);});Call Signature
Section titled “Call Signature”<
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.
Type Parameters
Section titled “Type Parameters”A
I
R
Parameters
Section titled “Parameters”schema
Section titled “schema”Schema<A, I, R>
Returns
Section titled “Returns”(
request):Effect<A,MalformedJsonError|FetchError|AbortError|NotAllowedError|ParseError|NotOkError,Fetch|R>
Parameters
Section titled “Parameters”request
Section titled “request”Returns
Section titled “Returns”Effect<A, MalformedJsonError | FetchError | AbortError | NotAllowedError | ParseError | NotOkError, Fetch | R>
0.1.0
Example
Section titled “Example”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
Example
Section titled “Example”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);});