Registry / devops / rest-api-handler

rest-api-handler

JSON →
library2.22.18jsnpmunverified

A lightweight HTTP client library for making REST API requests, built on top of the Fetch API. Current stable version is 2.22.18. It provides a simple Api class with methods for GET, POST, PUT, DELETE, and custom requests. Ships TypeScript definitions. Supports custom response processors, default headers, multiple data formats (JSON, FormData), and query parameter encoding. Unlike axios or node-fetch, it leverages the Fetch API standard and requires a polyfill for Node.js. Ideal for browser and Node.js environments with minimal configuration. Release cadence is irregular but maintained.

npm install rest-api-handler
INSTALL
IMPORT
SIG · REST-API-HANDLER
R
rest-api-handler
devopsjavascriptv2.22.18
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Api
import { Api } from 'rest-api-handler'
const Api = require('rest-api-handler').Api
ESM named export; CJS require is also valid but use named destructuring.
DefaultResponseProcessor
import { DefaultResponseProcessor } from 'rest-api-handler'
import DefaultResponseProcessor from 'rest-api-handler'
Named export, not default.
DefaultApiException
import { DefaultApiException } from 'rest-api-handler'
import { DefaultApiError } from 'rest-api-handler'
Exact name is DefaultApiException.

Shows how to create an Api instance with custom response processors and make a GET request with typed response.

import { Api, defaultResponseProcessor, DefaultApiException } from 'rest-api-handler'; const api = new Api('https://api.blockcypher.com', [ new DefaultResponseProcessor(DefaultApiException), ]); api.get('v1/btc/main').then((response) => { console.log(response.code); // 200 console.log(response.data); // parsed JSON console.log(response.source); // original Response });
Debug
Known issues
gotchaUses Fetch API which is not available in Node.js without a polyfill
fix
Install and import a fetch polyfill such as 'cross-fetch' before using this library in Node: require('cross-fetch/polyfill');
affects: all
gotchaIn browsers, the Fetch API may not be supported in older browsers (e.g., IE11).
fix
Use a fetch polyfill for older browsers.
affects: all
breakingFrom version 2.x, the response object from default processor returns .code, .data, .source instead of raw Fetch Response.
fix
Update code to access response.code and response.data instead of response.status and response.json().
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: fetch is not a function
Fetch API not available in Node.js; no polyfill provided.
fix
Install cross-fetch: npm install cross-fetch --save, then add require('cross-fetch/polyfill'); at entry point.
Cannot find module 'rest-api-handler'
Package not installed or import path incorrect.
fix
Run npm install rest-api-handler --save and use correct import: import { Api } from 'rest-api-handler';
DefaultResponseProcessor is not a constructor
Incorrect import or misspelled class name.
fix
Use import { DefaultResponseProcessor } from 'rest-api-handler'; and ensure correct spelling.
Upgrade
Version history
2.22.18latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
rest-api-handler — npm install rest-api-handler · libregistry