Module @prelude-io/fetch - v1.6.3

A utility library for working with the Fetch API through the Prelude-IO's type-checking mechanisms.

@Prelude-IO/Fetch

npm version documentation

Prelude-IO aims to provide easy to use run- and compiletime type-safety combined with the benefits of immutability through [Prelude-ts]. This library adds a simple wrapper around fetch, to type-check your request and response bodies.

Example

import * as io from "@prelude-io/core";
import { ioFetch } from "@prelude-io/fetch";

const CatFact = io.Complex("CatFact", {
fact: io.string,
length: io.positiveNumber,
});

const CatFactsResponse = io.Complex("CatFactsResponse", {
factCount: io.positiveNumber,
facts: io.Vector(CatFact),
});

const CatFactRequest = io.JSON.chain(
io.Complex("CatFactRequest", {
facts: io.number,
})
);

const catFactFetch = ioFetch(CatFactsResponse, CatFactRequest);

const result = await catFactFetch("https://catfacts.example.com", {
body: { facts: 4 },
});

console.log(result); // => IORight containing `{ factCount: 4, facts: [...] }`

Documentation

You can read typedoc documentation here

Installation

npm install --save @prelude-io/core @prelude-io/fetch prelude-ts

Index

Type Aliases

Functions

Generated using TypeDoc