@prelude-io/fetch
TypeScript icon, indicating that this package has built-in type declarations

1.6.4 • Public • Published

@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

Package Sidebar

Install

npm i @prelude-io/fetch

Weekly Downloads

72

Version

1.6.4

License

ISC

Unpacked Size

9.42 kB

Total Files

4

Last publish

Collaborators

  • annoiiyed