{"id":17726,"library":"js-data-http","title":"JSData HTTP Adapter","description":"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.","status":"abandoned","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/js-data/js-data-http","tags":["javascript","ajax","axios","rest","adapter","http","fetch","browser","xhr","typescript"],"install":[{"cmd":"npm install js-data-http","lang":"bash","label":"npm"},{"cmd":"yarn add js-data-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add js-data-http","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as the core DataStore library that this adapter extends and registers with.","package":"js-data","optional":false}],"imports":[{"note":"Since v3.0.0-beta.3, the package no longer exports a default module; HttpAdapter must be imported as a named export for ESM.","wrong":"import HttpAdapter from 'js-data-http';","symbol":"HttpAdapter","correct":"import { HttpAdapter } from 'js-data-http';"},{"note":"For CommonJS, the HttpAdapter is available as a named property on the exported module, not as the default export.","wrong":"const HttpAdapter = require('js-data-http');","symbol":"HttpAdapter","correct":"const { HttpAdapter } = require('js-data-http');"},{"note":"In browser environments where js-data-http is loaded via a script tag, the HttpAdapter class is exposed under the global JSDataHttp object.","symbol":"HttpAdapter","correct":"const adapter = new window.JSDataHttp.HttpAdapter();"}],"quickstart":{"code":"import { DataStore } from 'js-data';\nimport { HttpAdapter } from 'js-data-http';\n\n// Initialize DataStore\nconst store = new DataStore();\n\n// Instantiate the HTTP Adapter with a base path\n// Use environment variable for API_URL, falling back to a placeholder\nconst httpAdapter = new HttpAdapter({\n  basePath: process.env.API_URL ?? 'https://api.example.com/v1',\n  // Optionally configure default headers for all requests\n  // defaultHeaders: {\n  //   'X-API-KEY': 'your-api-key'\n  // },\n  // Optional: configure Axios instance if you have custom setup\n  // axios: myPreconfiguredAxiosInstance\n});\n\n// Register the HTTP adapter with the store, making it the default\nstore.registerAdapter('http', httpAdapter, { default: true });\n\n// Define a resource, which will use the default 'http' adapter\nconst User = store.defineResource({\n  name: 'users',\n  // idAttribute: 'id', // Default is 'id'\n});\n\nasync function fetchAndLogUsers() {\n  try {\n    // Perform a findAll operation, fetching users from basePath/users\n    const users = await User.findAll({}, {\n      // Optional: request-specific configuration\n      params: { limit: 5 }, // Adds ?limit=5 to the URL\n      headers: { 'X-Request-ID': 'unique-id-123' }\n    });\n    console.log('Successfully fetched users:', users);\n  } catch (error) {\n    console.error('Error fetching users:', error);\n    // Log detailed error from the adapter if available\n    if (error.response) {\n      console.error('API Response Error:', error.response.status, error.response.data);\n    }\n  }\n}\n\nfetchAndLogUsers();","lang":"typescript","description":"Demonstrates initializing a DataStore, registering the HttpAdapter, defining a resource, and performing a basic `findAll` operation to an API endpoint."},"warnings":[{"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.","message":"Starting 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.","severity":"breaking","affected_versions":">=3.0.0-beta.3"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=3.0.0-rc.1"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=3.0.1"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Use named imports: `import { HttpAdapter } from 'js-data-http';` for ESM or `const { HttpAdapter } = require('js-data-http');` for CommonJS.","cause":"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')`).","error":"TypeError: HttpAdapter is not a constructor"},{"fix":"Ensure you call `store.registerAdapter('http', httpAdapter, { default: true });` after creating your `HttpAdapter` instance and before defining resources or performing queries.","cause":"The `js-data` store was initialized, and resources were defined, but no HTTP adapter was registered or set as the default, preventing HTTP operations.","error":"Error: No default adapter is specified or no adapter is specified for resource \"users\""}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}