Registry / storage / xml-fetch

xml-fetch

JSON →
library1.1.91jsnpmunverified

A lightweight wrapper around XMLHttpRequest that provides a fetch-like API with promise-based requests. Version 1.1.91 supports GET, POST, PUT, DELETE, request aborting, and configurable timeout. Unlike native fetch, it supports upload progress and runs in older browsers lacking fetch support, but note the returned object is not a native Promise. TypeScript types are included. Release cadence is irregular.

npm install xml-fetch
INSTALL
IMPORT
SIG · XML-FETCH
X
xml-fetch
storagejavascriptv1.1.91
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.

http
import { http } from 'xml-fetch'
const http = require('xml-fetch').http
ESM-only; named import.
XmlFetch (default)
import XmlFetch from 'xml-fetch'
const XmlFetch = require('xml-fetch')
Default import gives XmlFetch class; use for direct instantiation.
HttpMethod type
import type { HttpMethod } from 'xml-fetch'
import { HttpMethod } from 'xml-fetch'
Type-only import for TypeScript; avoid runtime import.

Demonstrates GET, POST, and aborting a request using the named http import from xml-fetch.

import { http } from 'xml-fetch'; const API_URL = 'https://jsonplaceholder.typicode.com'; // GET request http.get(`${API_URL}/posts/1`) .then(response => console.log(response)) .catch(error => console.error(error)); // POST request with data http.post(`${API_URL}/posts`, { data: { title: 'foo', body: 'bar', userId: 1 } }) .then(response => console.log(response)) .catch(error => console.error(error)); // Abort request const request = http.get(`${API_URL}/posts`); setTimeout(() => request.abort(), 1000); request.catch(err => console.log('Aborted:', err));
Debug
Known issues
gotchaReturned value from http methods is not a native Promise; .then/.catch are available but it lacks Promise static methods like Promise.all.
fix
Do not use with Promise.all; handle requests individually.
affects: >=1.0.0
gotchaImport path: default export is XmlFetch class, named export is http. Mixing them incorrectly can lead to runtime errors.
fix
Use either 'import { http } from "xml-fetch"' or 'import XmlFetch from "xml-fetch"', not both.
affects: >=1.0.0
gotchatimeoutError option only applies when timeout is set; without timeout, timeoutError is ignored.
fix
Always set timeout when providing timeoutError.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught TypeError: xmlFetch.get is not a function
Importing default XmlFetch class instead of named http export
fix
Use 'import { http } from "xml-fetch"' or instantiate XmlFetch: const instance = new XmlFetch(); instance.get(...)
Uncaught (in promise) TypeError: Failed to execute 'open' on 'XMLHttpRequest'
URL has trailing comma or malformed string
fix
Check URL string: ensure no stray commas or spaces, e.g., http.get(`${API_URL}/${method}/`, { query }) but the code shows trailing comma after slash.
Upgrade
Version history
1.1.91latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
47 hits · last 30 days
node
42
Resources
xml-fetch — npm install xml-fetch · libregistry