Nanoscale Parts Manufacturing
    Have ideas to improve npm?Join in the discussion! »

    fp-fetch-es2020
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.2 • Public • Published

    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}`);
    };

    Install

    npm i fp-fetch-es2020

    DownloadsWeekly Downloads

    3

    Version

    0.1.2

    License

    MIT

    Unpacked Size

    16.1 kB

    Total Files

    18

    Last publish

    Collaborators

    • avatar