fetch-json-resource

Fetch JSON resource with AbortController and error handling

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
fetch-json-resource
2.0.04 years ago4 years agoMinified + gzip package size for fetch-json-resource in KB

Readme

Fetch JSON Resource

<img src="https://img.shields.io/npm/v/fetch-json-resource.svg" alt="npm version" >
<img src="https://img.shields.io/npm/l/fetch-json-resource.svg" alt="license">
<img src="https://david-dm.org/craftedsystems/fetch-json-resource/status.svg" alt="dependency status">
<img src="https://david-dm.org/craftedsystems/fetch-json-resource/dev-status.svg" alt="devDependencies status">


Code Smells Maintainability Rating Reliability Rating Security Rating SonarCloud Bugs Sonarcloud Status SonarCloud Vulnerabilities Technical Debt
Fetch JSON resource with AbortController and error handling.
  • no dependencies
  • ~600 bytes gzipped

Usage

# Install
npm i fetch-json-resource

import fetchJsonResource from 'fetch-json-resource';

fetchJsonResource('https://jsonplaceholder.typicode.com/todos/1')
  .then((json) => console.log(json))
  .catch((error) => console.log(error));

Options

You can add additional fetch options and/or a custom timeout value.
import fetchJsonResource from 'fetch-json-resource';

// Fetch options
const options = {};

// Abort after 5 seconds
const timeout = 5000;

fetchJsonResource('https://jsonplaceholder.typicode.com/todos/1', options, timeout)
  .then((json) => console.log(json))
  .catch((error) => console.log(error));