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

2.0.1 • Public • Published

fetch-utils

Build Status codecov npm Bundlephobia minified size

A collection of utilities for working with the Fetch API.

Installation

npm install @ultraq/fetch-utils

API

checkStatus(reponse)

Make sure the response from the server is an OK one, throwing an error if it isn't. Usually chained right after the fetch request, eg:

fetch(/* ... */)
  .then(checkStatus)
  .then(response => {
  	// ...
  });

responseAsJson(response)

Assumes a JSON response and attempts to parse and return it as a JavaScript object. Usually chained right after the response is deemed OK, eg:

fetch(/* ... */)
  .then(checkStatus)
  .then(responseAsJson)
  .then(object => {
  	// ...
  });

responseAsText(response)

Process the response body as a string. Usually chained right after the response is deemed OK, eg:

fetch(/* ... */)
  .then(checkStatus)
  .then(responseAsText)
  .then(string => {
  	// ...
  });

Dependencies (0)

    Dev Dependencies (10)

    Package Sidebar

    Install

    npm i @ultraq/fetch-utils

    Weekly Downloads

    11

    Version

    2.0.1

    License

    Apache-2.0

    Unpacked Size

    28.2 kB

    Total Files

    11

    Last publish

    Collaborators

    • ultraq