2.0.1 • Published 8 months ago

@ultraq/fetch-utils v2.0.1

Weekly downloads
97
License
Apache-2.0
Repository
github
Last release
8 months ago

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 => {
  	// ...
  });
2.0.1

8 months ago

2.0.0

8 months ago

1.1.0

4 years ago

1.0.0

5 years ago

0.1.0

5 years ago