Registry / database / js-data-http

js-data-http

JSON →
library3.0.1jsnpmunverified

This package provides an HTTP (XHR) adapter for the js-data ORM/ODM library, specifically designed for use in browser environments. Its primary function is to enable js-data to interact with RESTful APIs over HTTP, abstracting away direct XMLHttpRequest calls. The current stable version is 3.0.1, released in 2017. The project appears to be largely abandoned, with no significant updates or active development since then, implying a very slow, if any, future release cadence. It differentiates itself by tightly integrating with the js-data ecosystem, allowing developers to leverage js-data's data modeling, caching, and relationship management features while performing standard CRUD operations via HTTP requests. It utilizes XMLHttpRequest internally for its operations, and while Axios is mentioned as a development dependency, the core request mechanism relies on older browser APIs. Users should be acutely aware of its lack of recent maintenance when considering it for new projects, especially regarding security and modern browser compatibility.

npm install js-data-http
INSTALL
IMPORT
SIG · JS-DATA-HTTP
J
js-data-http
databasejavascriptv3.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

HttpAdapter
import { HttpAdapter } from 'js-data-http';
import HttpAdapter from 'js-data-http';
Since v3.0.0-beta.3, the package no longer exports a default module; HttpAdapter must be imported as a named export for ESM.
HttpAdapter
const { HttpAdapter } = require('js-data-http');
const HttpAdapter = require('js-data-http');
For CommonJS, the HttpAdapter is available as a named property on the exported module, not as the default export.
HttpAdapter
const adapter = new window.JSDataHttp.HttpAdapter();
In browser environments where js-data-http is loaded via a script tag, the HttpAdapter class is exposed under the global JSDataHttp object.

Demonstrates initializing a DataStore, registering the HttpAdapter, defining a resource, and performing a basic `findAll` operation to an API endpoint.

import { DataStore } from 'js-data'; import { HttpAdapter } from 'js-data-http'; // Initialize DataStore const store = new DataStore(); // Instantiate the HTTP Adapter with a base path // Use environment variable for API_URL, falling back to a placeholder const httpAdapter = new HttpAdapter({ basePath: process.env.API_URL ?? 'https://api.example.com/v1', // Optionally configure default headers for all requests // defaultHeaders: { // 'X-API-KEY': 'your-api-key' // }, // Optional: configure Axios instance if you have custom setup // axios: myPreconfiguredAxiosInstance }); // Register the HTTP adapter with the store, making it the default store.registerAdapter('http', httpAdapter, { default: true }); // Define a resource, which will use the default 'http' adapter const User = store.defineResource({ name: 'users', // idAttribute: 'id', // Default is 'id' }); async function fetchAndLogUsers() { try { // Perform a findAll operation, fetching users from basePath/users const users = await User.findAll({}, { // Optional: request-specific configuration params: { limit: 5 }, // Adds ?limit=5 to the URL headers: { 'X-Request-ID': 'unique-id-123' } }); console.log('Successfully fetched users:', users); } catch (error) { console.error('Error fetching users:', error); // Log detailed error from the adapter if available if (error.response) { console.error('API Response Error:', error.response.status, error.response.data); } } } fetchAndLogUsers();
Debug
Known issues
breakingStarting from v3.0.0-beta.3, the package changed its export mechanism from a default export to a named export. This requires updating import statements.
fix
Change `import HttpAdapter from 'js-data-http'` to `import { HttpAdapter } from 'js-data-http'` for ESM, and `const HttpAdapter = require('js-data-http')` to `const { HttpAdapter } = require('js-data-http')` for CommonJS.
affects: >=3.0.0-beta.3
breakingVersion 3.0.0-rc.1 and later of `js-data-http` strictly depends on `js-data` version 3.0.0-rc.4 or greater. Incompatible `js-data` versions will lead to runtime errors.
fix
Ensure your `js-data` package is at version `3.0.0-rc.4` or higher (preferably a stable v3.x release) to match the adapter's requirements.
affects: >=3.0.0-rc.1
gotchaThe `js-data-http` project appears to be abandoned, with its last major release (v3.0.1) in 2017. This means it no longer receives updates, security patches, or bug fixes, making it potentially vulnerable or incompatible with modern browser environments and JavaScript language features.
fix
Consider migrating to a more actively maintained data layer or HTTP client library. If continuing to use, thoroughly audit the codebase for security vulnerabilities and prepare for manual maintenance.
affects: >=3.0.1
Errors
Common errors & fixes
TypeError: HttpAdapter is not a constructor
Attempting to instantiate `HttpAdapter` after importing it incorrectly as a default export (e.g., `import HttpAdapter from 'js-data-http'`) or as the entire module in CommonJS (`const HttpAdapter = require('js-data-http')`).
fix
Use named imports: `import { HttpAdapter } from 'js-data-http';` for ESM or `const { HttpAdapter } = require('js-data-http');` for CommonJS.
Error: No default adapter is specified or no adapter is specified for resource "users"
The `js-data` store was initialized, and resources were defined, but no HTTP adapter was registered or set as the default, preventing HTTP operations.
fix
Ensure you call `store.registerAdapter('http', httpAdapter, { default: true });` after creating your `HttpAdapter` instance and before defining resources or performing queries.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
js-datarequiredRequired as the core DataStore library that this adapter extends and registers with.
Agent activity
6 hits · last 30 days
node
6
Resources
js-data-http — npm install js-data-http · libregistry