{"id":15522,"library":"aurelia-fetch-client","title":"Aurelia Fetch Client","description":"aurelia-fetch-client provides a straightforward HTTP client built upon the standard Fetch API, tailored for use within the Aurelia framework ecosystem. It is currently at version 1.8.2 and receives updates with a relatively moderate cadence, primarily for bug fixes and minor feature enhancements. Key differentiators include its seamless integration with Aurelia's dependency injection and plugin system, offering features like request interception, retry functionality (since 1.4.0), and helper methods for common HTTP verbs. While designed for Aurelia, it can function in any JavaScript environment, though a Fetch API polyfill (e.g., `whatwg-fetch`) is often required for broader browser or Node.js compatibility. It ships with TypeScript types, facilitating robust development.","status":"active","version":"1.8.2","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/aurelia/fetch-client","tags":["javascript","aurelia","http","ajax","fetch","typescript"],"install":[{"cmd":"npm install aurelia-fetch-client","lang":"bash","label":"npm"},{"cmd":"yarn add aurelia-fetch-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add aurelia-fetch-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for environments that do not natively support the Fetch API (e.g., older browsers, some Node.js versions).","package":"whatwg-fetch","optional":true}],"imports":[{"note":"Primary class for making HTTP requests. Aurelia applications typically inject this.","wrong":"const HttpClient = require('aurelia-fetch-client').HttpClient;","symbol":"HttpClient","correct":"import { HttpClient } from 'aurelia-fetch-client';"},{"note":"A helper function for setting the Content-Type header to `application/json` and stringifying the body. Note the lowercase 'j'.","wrong":"import { JSON } from 'aurelia-fetch-client';","symbol":"json","correct":"import { json } from 'aurelia-fetch-client';"},{"note":"TypeScript interface for Fetch API request options, re-exported for convenience and type safety.","symbol":"RequestInit","correct":"import { RequestInit } from 'aurelia-fetch-client';"}],"quickstart":{"code":"import { HttpClient, json } from 'aurelia-fetch-client';\n\n// For environments without native Fetch, a polyfill is needed.\n// import 'whatwg-fetch'; // Polyfill example\n\nasync function fetchData() {\n  const client = new HttpClient();\n\n  try {\n    // Configure the client globally or per-request\n    client.configure(config => {\n      config\n        .useStandardConfiguration()\n        .withBaseUrl('https://jsonplaceholder.typicode.com/');\n    });\n\n    // Make a GET request\n    const getResponse = await client.fetch('posts/1');\n    const getData = await getResponse.json();\n    console.log('GET Data:', getData);\n\n    // Make a POST request with JSON payload\n    const postResponse = await client.post('posts', json({\n      title: 'foo',\n      body: 'bar',\n      userId: 1,\n    }));\n    const postData = await postResponse.json();\n    console.log('POST Data:', postData);\n\n  } catch (error) {\n    console.error('Fetch error:', error);\n  }\n}\n\nfetchData();","lang":"typescript","description":"Demonstrates initializing HttpClient, configuring a base URL, and performing GET and POST requests with JSON data."},"warnings":[{"fix":"Install `whatwg-fetch` (`npm install whatwg-fetch`) and import it at the application entry point: `import 'whatwg-fetch';`","message":"When running in environments that do not natively support the Fetch API (e.g., older browsers or some Node.js versions), a polyfill like `whatwg-fetch` is required. The library itself does not bundle one.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review type definitions and ensure proper typing when upgrading. If using JavaScript, be aware of potentially stricter runtime checks in some edge cases introduced by the TS conversion.","message":"Version 1.8.0 introduced a conversion to TypeScript. While largely compatible, subtle type changes or stricter compilation might affect existing JavaScript codebases relying on implicit behaviors or incorrect typings.","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Use `json(data)` exclusively for automatically handling JSON serialization and content-type. For other content types or pre-stringified data, set `headers` and `body` directly in `RequestInit`.","message":"The `json()` helper function for POST/PUT requests automatically sets the `Content-Type` header to `application/json` and stringifies the body. If you manually set `Content-Type` or provide a pre-stringified body, it might lead to unexpected header or body formats.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If experiencing module resolution issues, ensure your build setup correctly handles native ESM or CommonJS. Upgrading to 1.8.1 or later generally resolves the specific `es2015 back to native-modules` issue.","message":"Between versions 1.8.0 and 1.8.1/1.8.2, there were changes related to ES2015 module output, specifically reverting 'es2015 back to native-modules'. This could impact build processes or module resolution in specific tooling setups if not aligned with the expected module format.","severity":"gotcha","affected_versions":"1.8.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Install a Fetch polyfill (e.g., `whatwg-fetch`) and import it before `aurelia-fetch-client` usage: `import 'whatwg-fetch';`","cause":"The environment where `aurelia-fetch-client` is running does not natively provide the Fetch API.","error":"ReferenceError: fetch is not defined"},{"fix":"Ensure the package is installed (`npm install aurelia-fetch-client`) and that your bundler/runtime is configured to resolve node_modules.","cause":"The package is not installed or the module resolver cannot find it.","error":"Error: Cannot find module 'aurelia-fetch-client'"},{"fix":"These helper methods were added in version 1.5.0. Upgrade `aurelia-fetch-client` to version 1.5.0 or higher to use them.","cause":"Attempting to use `post`, `get`, `put`, `delete` helper methods on an older version of `HttpClient`.","error":"TypeError: client.post is not a function"}],"ecosystem":"npm"}