Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fp-fetch

monstasat129MIT0.1.1TypeScript support: included

Functional style, non-throwing fetch utils

fetch-api, typescript, functional-programming, fp-ts

readme

fp-fetch

Functional style, non-throwing utils for data fetching

Installation

To install the stable version:

npm install fp-fetch

Usage

Basic example

import { isLeft } from 'fp-ts/lib/Either';
import {
  NetworkError,
  ParserError,
  ResponseError,
  fetchJSON
} from 'fp-fetch';

const result = await fetchJSON('http://example.com')();

if (isLeft(result)) {
  // handle error here
  const { left: error } = result;
  if (error instanceof NetworkError) {
    console.log(`network error occured, message=${error.message}`);
  }
  if (error instanceof ParserError) {
    console.log(`parser error occured, message=${error.message}`);
  }
  if (error instanceof ResponseError) {
    const { message, body } = error;
    console.log(`response error occured, message=${message}, body=${body}`);
  }
} else {
  // handle ok here
  const { right: payload } = result;
  console.log(`got ok response, payload=${payload}`);
};

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

0.1.1

5 May 2020

  • chore: rename TaskEither to FetchTask in pipe example a954e5d
  • docs: minor grammar typos fix 540d33f

0.1.0

5 May 2020

  • chore: initial commit 912a5d6
  • chore: add release-it & auto-changelog to dev dependencies 79a21c5
  • docs(examples): add basic example to README.md and /examples dir d548904